fork download
  1. def word_count(mystr):
  2. myl = mystr.lower().split()
  3. dic = {}
  4. for value in myl:
  5. if dic.has_key(value):
  6. dic[value]+=1
  7. else:
  8. dic[value]=1
  9. return dic
  10. print word_count("The cat sat at the mat")
Success #stdin #stdout 0s 23304KB
stdin
Standard input is empty
stdout
{'the': 2, 'sat': 1, 'mat': 1, 'at': 1, 'cat': 1}