Dictionary sorting

John Gordon gordon at panix.com
Thu Nov 3 14:57:27 EDT 2011


In <16245908.783.1320346014867.JavaMail.geo-discussion-forums at yqhd1> Scott Ware <scottdware at gmail.com> writes:

> Python newbie here. So, when creating dictionaries, I am noticing that
> each time I print it out, that its not in the same order as when I typed
> it in. They seem to be getting sorted somehow. Is there a way to not sort
> them and leave the order as is?

Dictionaries don't maintain the order of the items.

If you want to keep track of the order in which the items were inserted,
you'll need to do that yourself using a separate mechanism (a list, for
example.)

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list