Created
November 21, 2010 02:36
-
-
Save astrofrog/708383 to your computer and use it in GitHub Desktop.
Word count stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pipe text into this to get a word count list in decreasing order, e.g.: | |
# | |
# $ detex ms.tex | python wordcount.py | |
# model:9 | |
# star:8 | |
# formation:7 | |
# YSOs:7 | |
# ... | |
import sys | |
text = sys.stdin.read() | |
text = text.replace('\n',' ') | |
words = text.split() | |
count = {} | |
for word in words: | |
if word in count: | |
count[word] += 1 | |
else: | |
count[word] = 1 | |
values = list(set(count.values())) | |
values.sort() | |
values = values[::-1] | |
for value in values: | |
for word in count: | |
if count[word] == value: | |
print "%s:%i" % (word, count[word]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment