Re: Zipping a dictionary whose values are lists

2012-04-14 Thread Arnaud Delobelle
On 13 April 2012 17:35, Kiuhnm wrote: > On 4/13/2012 17:58, Alexander Blinne wrote: >> >> zip(*[x[1] for x in sorted(d.items(), key=lambda y: y[0])]) > > Or >  zip(*[d[k] for k in sorted(d.keys())]) .keys() is superfluous here: zip(*(d[k] for k in sorted(d))) -- Arnaud -- http://mail.pyth

Re: Zipping a dictionary whose values are lists

2012-04-13 Thread Kiuhnm
On 4/13/2012 17:58, Alexander Blinne wrote: Am 12.04.2012 18:38, schrieb Kiuhnm: Almost. Since d.values() = [[1,2], [1,2,3], [1,2,3,4]], you need to use list(zip(*d.values())) which is equivalent to list(zip([1,2], [1,2,3], [1,2,3,4])) Kiuhnm While this accidently works in this case

Re: Zipping a dictionary whose values are lists

2012-04-13 Thread Peter Otten
Alexander Blinne wrote: > zip(*[x[1] for x in sorted(d.items(), key=lambda y: y[0])]) Why not zip(*[x[1] for x in sorted(d.items())])? -- http://mail.python.org/mailman/listinfo/python-list

Re: Zipping a dictionary whose values are lists

2012-04-13 Thread Alexander Blinne
Am 12.04.2012 18:38, schrieb Kiuhnm: > Almost. Since d.values() = [[1,2], [1,2,3], [1,2,3,4]], you need to use > list(zip(*d.values())) > which is equivalent to > list(zip([1,2], [1,2,3], [1,2,3,4])) > > Kiuhnm While this accidently works in this case, let me remind you that d.values() do

RE: Zipping a dictionary whose values are lists

2012-04-13 Thread Shambhu Rajak
] Sent: 12/04/2012 9:58 PM To: python-list@python.org Subject: Zipping a dictionary whose values are lists I using Python 3.2 and have a dictionary >>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} whose values are lists I would like to zip into a list of tuples. If I explicitly write: >>

Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Dan Sommers
On Thu, 12 Apr 2012 09:28:03 -0700 (PDT) tkp...@gmail.com wrote: > I using Python 3.2 and have a dictionary > >>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} > > whose values are lists I would like to zip into a list of tuples. If > I explicitly write: > >>> list(zip([1,2], [1,2,3], [1,2,3,4]) > [(1, 1

Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Peter Otten
tkp...@gmail.com wrote: > I using Python 3.2 and have a dictionary d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} > > whose values are lists I would like to zip into a list of tuples. If I > explicitly write: list(zip([1,2], [1,2,3], [1,2,3,4]) > [(1, 1, 1), (2, 2, 2)] > > I get exactly what I

Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Kiuhnm
On 4/12/2012 18:28, tkp...@gmail.com wrote: I using Python 3.2 and have a dictionary d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} whose values are lists I would like to zip into a list of tuples. If I explicitly write: list(zip([1,2], [1,2,3], [1,2,3,4]) [(1, 1, 1), (2, 2, 2)] I get exactly what

Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Pavel Anossov
zip(*d.values()) On 12 April 2012 20:28, wrote: > I using Python 3.2 and have a dictionary d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} > > whose values are lists I would like to zip into a list of tuples. If I > explicitly write: list(zip([1,2], [1,2,3], [1,2,3,4]) > [(1, 1, 1), (2, 2, 2)]

Zipping a dictionary whose values are lists

2012-04-12 Thread tkpmep
I using Python 3.2 and have a dictionary >>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]} whose values are lists I would like to zip into a list of tuples. If I explicitly write: >>> list(zip([1,2], [1,2,3], [1,2,3,4]) [(1, 1, 1), (2, 2, 2)] I get exactly what I want. On the other hand, I have tried >