[Tutor] key/value order in dictionaries

Steve Poe steve.poe at gmail.com
Thu Jul 31 07:57:47 CEST 2008

Hi tutor list,

In dictionaries, I know that the keys are immutable, and the values
can change  What about the place/order of the key/order?  I thought
that they were sequential and they do not change.

 >>> D={"AAA":1234,"BBB":3456,"CCC":7890}
 >>> print D
{'AAA': 1234, 'BBB': 3456, 'CCC': 7890}
 >>> D={}
 >>> D={"AAA":1234,"BBB":3456,"CCC":7890,"DDD":5555,"EEE":6666,"FFF": 
 >>> print D
{'AAA': 1234, 'BBB': 3456, 'EEE': 6666, 'FFF': 7777, 'CCC': 7890,  
'DDD': 5555}

If I know the key, then I can find the value, so the order it is in  
the dictionary
should not matter. I am just curious  why this happens.  If I have (4)  
pairs, the display order is the same as I entered the them. With 5 or  
more key/value
dictionaries, the printed result is not sequential.

Any thoughts?


More information about the Tutor mailing list