##// END OF EJS Templates
Open 0.10.2 branch for development....
Open 0.10.2 branch for development. I don't expect to see much happen in this branch, but we'll have it available so people can contribute bug fixes and make pull requests. If we get enough contributions here, eventually we'll put a 0.10.2 release out.

File last commit:

r1337:53a3e331
r3134:8f60cada
Show More
wordfreq_skel.py
17 lines | 526 B | text/x-python | PythonLexer
"""Count the frequencies of words in a string"""
def wordfreq(text):
"""Return a dictionary of words and word counts in a string."""
def print_wordfreq(freqs, n=10):
"""Print the n most common words and counts in the freqs dict."""
words, counts = freqs.keys(), freqs.values()
items = zip(counts, words)
items.sort(reverse=True)
for (count, word) in items[:n]:
print word, count
if __name__ == '__main__':
import gzip
text = gzip.open('HISTORY.gz').read()
freqs = wordfreq(text)