Chapter 08

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

###################### 8.3 Word counting import string SampleString = "To be or not to be" occurrences = {} for word in string.

split(SampleString): occurrences[word] = occurrences.get(word, 0) + 1 for word in occurrences.keys(): print "The word", word, "occurs", occurrences[word], \ "time(s) in the string"

You might also like