Dictionary Keys question

Christian Heimes lists at cheimes.de
Wed Jan 30 17:59:55 EST 2008


FireNWater wrote:
> I'm curious why the different outputs of this code.  If I make the
> dictionary with letters as the keys, they are not listed in the
> dictionary in alphabetical order, but if I use the integers then the
> keys are in numerical order.
> 
> I know that the order of the keys is not important in a dictionary,
> but I was just curious about what causes the differences.  Thanks!!

Currently the order of dict keys depend on the hash of the object. Try
hash(1) and hash('a').




More information about the Python-list mailing list