Create dict from two lists
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Feb 10 09:41:43 EST 2006
py:
> Thanks, itertools.izip and just zip work great. However, I should have
> mentioned this, is that I need to keep the new dictionary sorted.
A Python dictionary is an unsorted data structure, so you cannot have
it sorted as you please.
(I have seen that lot of people ask for a sorted dictionary and for
permutation/combination functions, maybe they are batteries to be
included too in the standard library.)
If you need an ordered dict you can manage it yourself, keeping the
lists of keys, etc, or you can use an ordered dict implementation:
http://www.voidspace.org.uk/python/odict.html
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823
Etc.
Bye,
bearophile
More information about the Python-list
mailing list