Re: Why lambda in loop requires default?

2016-03-28 Thread Antoon Pardon
Op 27-03-16 om 03:46 schreef gvim: > Given that Python, like Ruby, is an object-oriented language why doesn't this: It has nothing to do with being object-oriented but by how scopes are used > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a Python doesn't create a

Re: Why lambda in loop requires default?

2016-03-27 Thread Terry Reedy
On 3/26/2016 9:46 PM, gvim wrote: Given that Python, like Ruby, is an object-oriented language why doesn't this: def m(): a = [] for i in range(3): a.append(lambda: i) return a def echo_i: return i b = m() for n in range(3): print(b[n]()) # => 2 2 2 ) # => 2 2 2 ...

Re: Why lambda in loop requires default?

2016-03-27 Thread Ned Batchelder
On Sunday, March 27, 2016 at 9:55:16 AM UTC-4, g vim wrote: > Given that Python, like Ruby, is an object-oriented language It turns out that "object-oriented" means very little, and lots of languages that are object-oriented will behave differently from each other, even where object behavior is

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 > > ... work the same as this in Ruby: > > def m > a = []

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 I'm going to suggest two variations that may or may not

Why lambda in loop requires default?

2016-03-27 Thread gvim
Given that Python, like Ruby, is an object-oriented language why doesn't this: def m(): a = [] for i in range(3): a.append(lambda: i) return a b = m() for n in range(3): print(b[n]()) # => 2 2 2 ... work the same as this in Ruby: def m a = [] (0..2).each {|i| a << ->(){i}} a