convert list of tuples into several lists
Pierre Barbier de Reuille
pierre.barbier at cirad.fr
Wed Feb 9 11:21:07 EST 2005
Oliver Eichler a écrit :
> 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
Best answer is : try it :)
use the "timeit" module (in the standard lib) to do so ...
Pierre
More information about the Python-list
mailing list