Re: [Tutor] Lamdas and locality

2007-03-04 Thread Michael Meier
Thanks for your answer and your workaround! There's always something to learn about lambdas and variable scope in Python ;) I'm sorry I didn't delete the quoted Tutor Digest part, it was a stupid mistake :( cheers, Michael ___ Tutor maillist - Tutor

Re: [Tutor] Lamdas and locality

2007-03-03 Thread Kent Johnson
Michael Meier wrote: > Hello > > I ran the following code in python: > ls = [(lambda op: op + i) for i in [1,2,3]] ls > [ at 0xb7de4cdc>, at 0xb7de4d14>, > at 0xb7de4d4c>] for l in ls: > ... print l(5) > ... > 8 > 8 > 8 > > > I am quite surprised of the result. I'

[Tutor] Lamdas and locality

2007-03-03 Thread Michael Meier
Hello I ran the following code in python: >>> ls = [(lambda op: op + i) for i in [1,2,3]] >>> ls [ at 0xb7de4cdc>, at 0xb7de4d14>, at 0xb7de4d4c>] >>> for l in ls: ... print l(5) ... 8 8 8 >>> I am quite surprised of the result. I'm generating three lamdas. What I want to do is that