large dictionary creation takes a LOT of time.

Ville Vainio ville at spammers.com
Fri Apr 29 06:53:11 EDT 2005


>>>>> "Kent" == Kent Johnson <kent37 at tds.net> writes:

    Kent> if frequency.has_key(word):
    Kent> frequency[word] += 1
    Kent> else:
    Kent> frequency[word] = 1

This is a good place to use 'get' method of dict:

frequency[word] = frequency.get(word,0) + 1

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list