Sorting distionary by value

John Machin sjmachin at lexicon.net
Thu Mar 28 04:41:01 EST 2002


Peter Hansen <peter at engcorp.com> wrote in message news:<3CA295CC.9682E2DB at engcorp.com>...
> 
> Something like   freq[word] = freq.get(word, 0) + 1
> 
> would probably be faster, and it's a little simpler I think,

Try this:

# way up front of the function, outside all loops
   freq = {}; freq_get = freq.get

# much later ...

      freq[word] = freq_get(word, 0) + 1



More information about the Python-list mailing list