On Friday 29 April 2005 11:53, Ville Vainio wrote:
> >>>>> "Kent" == Kent Johnson <[EMAIL PROTECTED]> 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

try/except might be fastest of all:

http://gumuz.looze.net/wordpress/index.php/archives/2005/04/28/python-dictionary-speed-optimisation/

Attachment: pgpyyTIumZQjr.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to