Dictionary from a list

Aahz aahz at pythoncraft.com
Sun Aug 23 15:11:05 CEST 2009

In article <baa0d11c-c999-4eee-9cf5-90ad667f5782 at b25g2000prb.googlegroups.com>,
EK  <ekayxu at gmail.com> wrote:
>On Aug 20, 2:10=A0pm, Peter Otten <__pete... at web.de> wrote:
>> >>> from itertools import izip
>> >>> it =3D iter([1,2,3,4,5,6])
>> >>> dict(izip(it, it))
>> {1: 2, 3: 4, 5: 6}

No, that's not a good solution.  For starters, it's less readable than
Peter's version.  More importantly, it has poor memory use because it
needs to construct both the intermediate tuple and the zip() list.
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I support family values -- Addams family values" --www.nancybuttons.com

More information about the Python-list mailing list