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

2009-05-26 Thread enzo michelangeli
Thanks guys. So far I had only come out with f = [eval('lambda x: x+'+str(j)) for j in range(3)] ...which I hated because, as everybody knows, eval is evil :-) Enzo On May 26, 5:20 pm, Arnaud Delobelle wrote: > "Diez B. Roggisch" writes: > > > You need to capture n into the closure of the lam

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

2009-05-26 Thread enzo michelangeli
Let's suppose I want to create a list of n functions of a single argument, returning the sum between argument and index in the list, so that e.g.: f[0](10) will return 10 f[3](12) will return 15 ...and so on. I had naively though of coding: f = [lambda x: x+j for j in range(n)] Unfortunately,