opposite of dict.items()

Raymond Hettinger vze4rx4y at verizon.net
Fri Aug 29 02:14:57 EDT 2003


[Tertius wrote]
> > Is there a method to create a dict from a list of keys and a list of
> > values ?

[Peter Otten]
> >>> dict(zip(range(3), "abc"))
> {0: 'a', 1: 'b', 2: 'c'}


If you're using Py2.3, then the itertools way is a bit nicer:

>>> dict(itertools.izip(range(3), "abc"))
{0: 'a', 1: 'b', 2: 'c'}


Raymond Hettinger






More information about the Python-list mailing list