[Edu-sig] How do we tell truths that might hurt

Arthur ajsiegel at optonline.net
Fri Apr 23 06:28:48 EDT 2004


Terry - 
> 
> import re, string
> 
> illegal_re = re.compile(r'[^a-zA-Z\s]+')

Huh?

> words = [w for w in illegal_re.sub(' ', open('myfile',
> 'r').read()).lower().split() if len(w)>2]

Whoa?

> 
> word_freq = {}
> for word in words:
>     word_freq[word] = word_freq.get(word, 0) + 1
> 
> word_freq = word_freq.items()
> word_freq.sort(lambda a,b: cmp(b[1],a[1]))

Hmmm?

> 
> for word, freq in word_freq[:500]:
>     print "%30s  %10d" % (word, freq)

??
 
> Now that wasn't terribly difficult, was it? ;-)

Piece of cake!

Art




More information about the Edu-sig mailing list