Dictionary Bug ? Python 1.5 & 2.2

Alex Martelli aleax at aleax.it
Sun Jan 6 06:10:39 EST 2002


A.A wrote:
        ...
> I'm not sure if I should call this a bug, but it certainly is very
> strange behaviour...
        ...
>>>> # The result is DISPLAYED in jumpled order
>     {'h': [], 'f': [], 'g': [], 'd': [], 'e': [], 'b': [], 'c': [], 'a':

It's definitely not a bug, and there's nothing particularly strange about 
it: a Python dictionary has no specified nor intrinsic "key order".  This 
allows the implementation to carry no "dead baggage" of ordering in that 
vast majority of cases where ordering is irrelevant, and reach excellent 
performance through 'hashing' techniques.

See: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52306
for ordering by-keys, and:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52231
for ordering by-values.


Alex




More information about the Python-list mailing list