opposite of dict.items()
Peter Abel
p-abel at t-online.de
Fri Aug 29 07:31:31 EDT 2003
"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message news:<BbC3b.11252$v57.8126 at nwrdny02.gnilink.net>...
> [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
I guess Py2.2 is nice too :-)
>>> dict(zip(range(3), "abc"))
{0: 'a', 1: 'b', 2: 'c'}
Regards
Peter
More information about the Python-list
mailing list