Re: Dictionary from a list

2009-08-23 Thread Aahz
In article , EK wrote: >On Aug 20, 2:10=A0pm, Peter Otten <__pete...@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} > >dict(zip(*[iter(l)]*2)) No, that's not a good solution. For starters, it's less reada

Re: Dictionary from a list

2009-08-22 Thread EK
On Aug 20, 2:10 pm, Peter Otten <__pete...@web.de> wrote: > Jan Kaliszewski wrote: > > 20-08-2009 o 02:05:57 Jan Kaliszewski wrote: > > >> Or probably better: > > >>      from itertools import islice, izip > >>      dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) > > > Or similarly, per

Re: Dictionary from a list

2009-08-20 Thread iu2
On Aug 20, 9:10 am, Peter Otten <__pete...@web.de> wrote: > Jan Kaliszewski wrote: > > 20-08-2009 o 02:05:57 Jan Kaliszewski wrote: > > >> Or probably better: > > >>      from itertools import islice, izip > >>      dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) > > > Or similarly, per

Re: Dictionary from a list

2009-08-20 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 20 Aug 2009 08:10:28 +0200, Peter Otten wrote: > > >> I just can't stop posting this one: >> > from itertools import izip > it = iter([1,2,3,4,5,6]) > dict(izip(it, it)) >> {1: 2, 3: 4, 5: 6} >> >> I really tried, but yours drove me over the edge. >

Re: Dictionary from a list

2009-08-20 Thread Tim Chase
Peter Otten wrote: it = iter([1,2,3,4,5,6]) dict(izip(it, it)) {1: 2, 3: 4, 5: 6} Zip(it). Zip(it) good. it's-3:00am-and-i-seriously-need-to-sleep'ly yers... -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary from a list

2009-08-20 Thread Steven D'Aprano
On Thu, 20 Aug 2009 08:10:28 +0200, Peter Otten wrote: > I just can't stop posting this one: > from itertools import izip it = iter([1,2,3,4,5,6]) dict(izip(it, it)) > {1: 2, 3: 4, 5: 6} > > I really tried, but yours drove me over the edge. If you want something to drive you ove

Re: Dictionary from a list

2009-08-19 Thread Peter Otten
Jan Kaliszewski wrote: > 20-08-2009 o 02:05:57 Jan Kaliszewski wrote: > >> Or probably better: >> >> from itertools import islice, izip >> dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) > > Or similarly, perhaps more readable: > > iterator = iter(li) > dict((ite

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
20-08-2009 o 02:05:57 Jan Kaliszewski wrote: Or probably better: from itertools import islice, izip dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) Or similarly, perhaps more readable: iterator = iter(li) dict((iterator.next(), iterator.next()) for i in xrange(l

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
19-08-2009 o 22:52:54 iu2 wrote: On Aug 19, 11:39 pm, "Diez B. Roggisch" wrote: iu2 schrieb: > Hi all, > I need to create a dictionary out of a list. > Given the list [1, 2, 3, 4, 5, 6] > I need the dictionary: {1:2, 3:4, 5:6} dict(zip(l[::2], l[1::2])) Or (for long lists, when memory

Re: Dictionary from a list

2009-08-19 Thread iu2
On Aug 19, 11:39 pm, "Diez B. Roggisch" wrote: > iu2 schrieb: > > > Hi all, > > > I need to create a dictionary out of a list. > > > Given the list [1, 2, 3, 4, 5, 6] > > > I need the dictionary: {1:2, 3:4, 5:6} > > dict(zip(l[::2], l[1::2])) > > Diez Wow, this is cool! thanks iu2 -- http://mai

Re: Dictionary from a list

2009-08-19 Thread Diez B. Roggisch
iu2 schrieb: Hi all, I need to create a dictionary out of a list. Given the list [1, 2, 3, 4, 5, 6] I need the dictionary: {1:2, 3:4, 5:6} dict(zip(l[::2], l[1::2])) Diez -- http://mail.python.org/mailman/listinfo/python-list