Displaying a list of words from a text followed by the number of times they appear
Revision as of 14:13, 16 March 2011 by Aymeric Mansoux (talk | contribs) (Created page with "<source lang="python"> #!/usr/bin/env python import sys, string words = {} for line in sys.stdin: for word in line.split(): word = word.lower().strip(string.punctua...")
#!/usr/bin/env python
import sys, string
words = {}
for line in sys.stdin:
for word in line.split():
word = word.lower().strip(string.punctuation)
words[word] = words.get(word, 0) + 1
for (word, count) in sorted(words.items()):
print word, count