Sorting distionary by value

Jeff Shannon jeff at ccvcorp.com
Thu Mar 28 15:01:15 EST 2002


phil hunt wrote:

> IIRC in Awk you can just say:   freq[word] ++ and it works
> correctly even when there is no pre-existing index of word in freq.
>
> IMO it's a pity Python isn't like that.

I disagree.  I'm just as happy that Python doesn't try to guess what would be a
suitable "default" value for non-existent keys.  It seems to me to be entirely
consistent with the philosophy of "explicit is better than implicit".  Why
presume that somedict[key] should default to 0, instead of to an empty string,
or to None, or to [], or...  ???

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list