Reversing a dict?

Ian Kelly ian.g.kelly at gmail.com
Tue May 6 12:01:04 EDT 2008


On Tue, May 6, 2008 at 9:26 AM, Jeremy Sanders
<jeremy+complangpython at jeremysanders.net> wrote:
> krumblebunk at gmail.com wrote:
>
>  > Hi - further to my earlier query regarding partial matches (which with
>  > all your replies enabled me to advance my understanding, thanks), I
>  > now need to reverse a dict.
>
>  There is no guaranteed order to the items stored in a dictionary. They can
>  and will move around as the dict is modified. Have a look at
>  diveintopython:
>
>  http://www.diveintopython.org/getting_to_know_python/dictionaries.html
>
>  You'll have to store your keys in a list or tuple to keep them ordered.

You might also take a look at the odict[1] or ordereddict[2] modules.

[1] http://www.voidspace.org.uk/python/odict.html
[2] http://www.xs4all.nl/~anthon/Python/ordereddict/



More information about the Python-list mailing list