[Tutor] Keeping Dictonary Entries Ordered

Alan Gauld alan.gauld at btinternet.com
Thu Feb 12 10:28:23 CET 2009


"Eric Dorsey" <dorseye at gmail.com> wrote 

>>>> config_names
> {'start_time': '18:00:00', 'gray_scale': True, 'long': 120.0}
>>>> for i, x in config_names.items():
> ...     print i, x
> ...
> start_time 18:00:00
> gray_scale True
> long 120.0

Thats pretty much a happy coincidence, there is no guarantee 
that it will work like that for all dictionaries:

>>> d = {1:2,3:4,8:9,5:7}
>>> for i,x in d.items(): print i,x
...     
8 9
1 2
3 4
5 7

Alan G.



More information about the Tutor mailing list