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) {}
>>>
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
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
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
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
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
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
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
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
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
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>
What does the leading * do?
--
http://mail.python.org/mailman/listinfo/python-list
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'
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
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
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),
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])
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[
zip(*[(1,4),(2,5),(3,6)])
--
Regards,
Diez B. Roggisch
--
http://mail.python.org/mailman/listinfo/python-list
19 matches
Mail list logo