Beginner question - How to effectively pass a large list
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Wed Dec 17 01:12:05 EST 2003
> From: J.R.
[snip the results of some pretty good investigation and reasoning]
> I think we could eliminate such accumulation effect by
> changing the function
> as follow:
> >>> def f(d=[]):
> d = d+[0]
> print d
The above would work in this case, but is not the canonical way.
def f (d=None):
if d is None:
d = []
d.append(0)
print d
i.e. use None as a sentinel, and if no parameter is passed create a list to use. In particular, your version uses a different interface to perform the append - d.__add__(list) rather than d.append(int).
Tim Delaney
More information about the Python-list
mailing list