Auto sort in Dictionaries???
Jeff Davis
jdavis at empires.org
Mon Jul 23 04:33:43 EDT 2001
phillip wrote:
> Hi,
>
> I put 'name,values' into a dictionary.
> But when I get the keys and display the values they come out in a
> different order that the order I inserted them in.
>
> Is there a way maintain the oringinal order?
>
> Phill
>
I don't think dictionaries are designed that way in python, but here is
what you can do: each new value you insert, push() the key onto a list.
Then when you need to access them in order just traverse the list.
The reason you most likely didn't get the values back in order is that the
DB in which the values were inserted used an algorithm for data management
that didn't preserve the order.
I am not sure this is the best solution, but it will work.
Hope it helps.
Jeff Davis
More information about the Python-list
mailing list