arg-passing style question
Guy Middleton
guy at obstruction-no-spam.com
Sun Apr 20 14:10:28 EDT 2003
In article <A4ioa.87812$Vzu.36931 at news02.bloor.is.net.cable.rogers.com>,
Guy Middleton <guy at obstruction-no-spam.com> wrote:
> I want to pass two values to a function that expects a single argument.
>
> So, I could wrap them in either a list or a tuple. Is either way preferred
> over the other?
Tuples appear to be faster, enough to make a difference if I'm doing lots of
these:
>>> setup = """
... a = 1
... b = 2
... def fn(x):
... pass
... """
>>> print timeit.Timer("fn((a,b))", setup, clock).repeat()
[2.90625, 2.921875, 2.921875]
>>> print timeit.Timer("fn([a,b])", setup, clock).repeat()
[4.5859375, 4.6015625, 4.5859375]
>>>
More information about the Python-list
mailing list