Autogenerate functions (array of lambdas)

Duncan Booth duncan.booth at invalid.invalid
Thu Sep 6 04:52:02 EDT 2007


Chris Johnson <effigies at gmail.com> wrote:

> 2) Is there a better or preferred method than the one I've found?
> 

Use function default arguments to keep the current value of i at the point 
where you define the function.

a = [(lambda n=i: n) for i in range(10)]




More information about the Python-list mailing list