Dictionaries again - where do I make a mistake?

Dustin J. Mitchell dustin at v.igoro.us
Thu Oct 19 17:46:27 CEST 2006

Lad wrote:
> Sorting seems to be OK,.
> the command
> print key,val
> prints the proper values
>  but I can not create Newdict to be sorted properly.
> Where do I make a mistake?
> Thank you for help.

Dictionaries are unordered -- the order in which items come out is
unspecified.  It's based on the details of their internal storage mechanism (a
hash table), and you can't control it at all.

If you need your pairs in a certain order, you'll have to use a list of tuples.


More information about the Python-list mailing list