How to create a list of functions depending on a parameter?

Diez B. Roggisch deets at nospam.web.de
Tue May 26 12:39:08 CEST 2009


Arnaud Delobelle wrote:

> "Diez B. Roggisch" <deets at nospam.web.de> writes:
> 
>> You need to capture n into the closure of the lambda:
>>
>> f = [lambda x, n=n: x+j for j in xrange(n)]
> 
> You mean  [lambda x, j=j: x+j for j in xrange(n)]


Ah, sorry, parentheses-problem.

Diez





More information about the Python-list mailing list