lambda-funcs problem
Ryan Ginstrom
software at ginstrom.com
Wed Sep 19 08:03:04 EDT 2007
More information about the Python-list mailing list
Wed Sep 19 08:03:04 EDT 2007
- Previous message (by thread): lambda-funcs problem
- Next message (by thread): lambda-funcs problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> On Behalf Of dmitrey.kroshko at scipy.org > F = [] > for i in xrange(N): > F.append(lambda x: x + i) > > however, the example don't work - since i in end is N-1 it yields x+ > (N-1) for any func. How about: >>> def make_adder(i): def adder(x): return x+i return adder >>> funcs = [make_adder(i) for i in xrange(10)] >>> print [func(10) for func in funcs] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> Regards, Ryan Ginstrom
- Previous message (by thread): lambda-funcs problem
- Next message (by thread): lambda-funcs problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list