Re: convert list of tuples into several lists

2005-02-11 Thread Steven Bethard
Pierre Quentel wrote: Could someone explain why this doesn't work : Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(*args,**kw): ... print args, kw ... >>> f(*[1,2]) (1, 2) {} >>>

Re: convert list of tuples into several lists

2005-02-11 Thread Nick Coghlan
Peter Hansen wrote: Is there some unexpected limit to the number of arguments that may be passed with the *args format (say, "256 function arguments maximum are supported by Python"), or is this concern just because of the raw memory inherently used by the tuple? In other words, if one is confident

Re: convert list of tuples into several lists

2005-02-10 Thread Stephen Thorne
On Fri, 11 Feb 2005 07:35:43 +0100, Pierre Quentel <[EMAIL PROTECTED]> wrote: > Steven Bethard a écrit : > > Cappy2112 wrote: > > > >> What does the leading * do? > > > > > > Tells Python to use the following iterable as the (remainder of the) > > argument list: > > > > Could someone explain why t

Re: convert list of tuples into several lists

2005-02-10 Thread Pierre Quentel
Steven Bethard a écrit : Cappy2112 wrote: What does the leading * do? Tells Python to use the following iterable as the (remainder of the) argument list: Could someone explain why this doesn't work : Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "co

Re: convert list of tuples into several lists

2005-02-10 Thread Cappy2112
Thanks I dont remember reading anything about this. What is this feature called? Steven Bethard wrote: > Cappy2112 wrote: > > What does the leading * do? > > Tells Python to use the following iterable as the (remainder of the) > argument list: > > -- http://mail.python.org/mailman/listinfo/pyth

Re: convert list of tuples into several lists

2005-02-10 Thread Peter Hansen
Nick Coghlan wrote: I never really got the impression that Guido was particularly *strongly* opposed to this use of the extended call syntax. Merely that he was concerned that it would break down if the relevant list turned out to be large (that is, the abuse is using *args with a list when the

Re: convert list of tuples into several lists

2005-02-10 Thread Nick Coghlan
Steven Bethard wrote: Peter Hansen wrote: Steven Bethard wrote: Diez B. Roggisch wrote: zip(*[(1,4),(2,5),(3,6)]) While this is also the approach I would use, it is worth noting that Guido thinks of this as an abuse of the argument passing machinery: http://mail.python.org/pipermail/python-dev/2

Re: convert list of tuples into several lists

2005-02-10 Thread Nick Craig-Wood
Cappy2112 <[EMAIL PROTECTED]> wrote: > What does the leading * do? It causes the list/tuple following the * to be unpacked into function arguments. Eg >>> zip(*[(1, 2, 3), (4, 5, 6)]) [(1, 4), (2, 5), (3, 6)] is the same as >>> zip((1, 2, 3), (4, 5, 6)) [(1, 4), (2, 5), (3, 6)] The * should m

Re: convert list of tuples into several lists

2005-02-10 Thread Oliver Eichler
Pierre Barbier de Reuille wrote: > > Best answer is : try it :) > use the "timeit" module (in the standard lib) to do so ... Ok, (a second time. I hope the first post was cancelled as it was false) import timeit s = """\ a,b,c1,c2 = zip(*[(x[2],x[4], x[2]-x[1], x[2] - x[3]) for x in z]) """ t

Re: convert list of tuples into several lists

2005-02-10 Thread Oliver Eichler
Pierre Barbier de Reuille wrote: > Best answer is : try it :) > use the "timeit" module (in the standard lib) to do so ... Ok, import timeit s = """\ a,b,c1,c2 = zip(*[(x[2],x[4], x[2]-x[1], x[2] - x[3]) for x in z]) """ t = timeit.Timer(stmt=s,setup="z = [(1,2,3,4,5)]*1000") print "%.2f usec/p

Re: convert list of tuples into several lists

2005-02-10 Thread Steven Bethard
Cappy2112 wrote: What does the leading * do? Tells Python to use the following iterable as the (remainder of the) argument list: py> def f(x, y): ... print x, y ... py> f([1, 2]) Traceback (most recent call last): File "", line 1, in ? TypeError: f() takes exactly 2 arguments (1 given) py>

Re: convert list of tuples into several lists

2005-02-09 Thread Cappy2112
What does the leading * do? -- http://mail.python.org/mailman/listinfo/python-list

Re: convert list of tuples into several lists

2005-02-09 Thread Steven Bethard
Peter Hansen wrote: Steven Bethard wrote: Diez B. Roggisch wrote: zip(*[(1,4),(2,5),(3,6)]) While this is also the approach I would use, it is worth noting that Guido thinks of this as an abuse of the argument passing machinery: http://mail.python.org/pipermail/python-dev/2003-July/037346.html I'

Re: convert list of tuples into several lists

2005-02-09 Thread Peter Hansen
Steven Bethard wrote: Diez B. Roggisch wrote: zip(*[(1,4),(2,5),(3,6)]) While this is also the approach I would use, it is worth noting that Guido thinks of this as an abuse of the argument passing machinery: http://mail.python.org/pipermail/python-dev/2003-July/037346.html I'm not sure that's th

Re: convert list of tuples into several lists

2005-02-09 Thread Steven Bethard
Diez B. Roggisch wrote: zip(*[(1,4),(2,5),(3,6)]) While this is also the approach I would use, it is worth noting that Guido thinks of this as an abuse of the argument passing machinery: http://mail.python.org/pipermail/python-dev/2003-July/037346.html Steve -- http://mail.python.org/mailman/list

Re: convert list of tuples into several lists

2005-02-09 Thread Francis Girard
Le mercredi 9 Février 2005 14:46, Diez B. Roggisch a écrit : > zip(*[(1,4),(2,5),(3,6)]) > > -- > Regards, > > Diez B. Roggisch That's incredibly clever! I would had never thought to use "zip" to do this ! I would had only think to use it for the contrary, i.e. >>> zip([1,2,3], [4,5,6]) [(1, 4),

Re: convert list of tuples into several lists

2005-02-09 Thread Pierre Barbier de Reuille
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])

Re: convert list of tuples into several lists

2005-02-09 Thread Oliver Eichler
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[

Re: convert list of tuples into several lists

2005-02-09 Thread Diez B. Roggisch
zip(*[(1,4),(2,5),(3,6)]) -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list