convert list of tuples into several lists

Oliver Eichler oliver.eichler at dspsolutions.de
Wed Feb 9 11:04:28 EST 2005


Diez B. Roggisch wrote:

> zip(*[(1,4),(2,5),(3,6)])
> 
Thanks :) I knew it must be simple. The asterics - thing was new to me. 

By the way: What is faster?

this:

z = [(1,4),(2,5),(3,6)
a,b = zip(*[(x[0], x[0]-x[1]) for x in z])

or:

a = []
b = []
for x in z:
  a.append(x[0])
  b.append(x[0]-x[1])

I guess first, isn't it?


Oliver



More information about the Python-list mailing list