Optimizing a text statistics function
Benji York
_google at benjiyork.com
Wed Apr 21 15:32:46 EDT 2004
Nickolay Kolev <nmkolev at uni-bonn.de> wrote in message news:<c661pe$tie$1 at f1node01.rhrz.uni-bonn.de>...
> I find the two loops through the initial list a bit troubling. Could
> this be avoided?
How about instead of:
for x in strippedWords:
unique[x] = 0
for x in strippedWords:
unique[x] += 1
You do something like (untested):
for word in strippedWords:
unique[word] = unique.get(word, 0) + 1
--
Benji York
http://benjiyork.com
More information about the Python-list
mailing list