##// END OF EJS Templates
Fix minor error that I saw in some odd cases, not sure how to test for it....
Fix minor error that I saw in some odd cases, not sure how to test for it. Unfortunately I don't have a reliable test case for this, it's deep in traceback handling. But I did see a few times ultratb itself crash.

File last commit:

r1337:53a3e331
r2438:0e6b27d4
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)