dictionary

Peter Otten __peter__ at web.de
Mon Apr 26 20:28:40 CEST 2010


gopi krishna wrote:

> When I give a dictionary with key and value in order how can get back  iy
> in same order

You can't. You either have to maintain a list of the keys in parallel, or 
use an ordered dictionary like the following:

http://code.activestate.com/recipes/576693/

It will be included in Python 2.7 and already is in 3.1:

http://docs.python.org/py3k/library/collections.html#collections.OrderedDict

Peter




More information about the Python-list mailing list