Maybe it’s just too late, but this python behavior is confusing:

arr = [1,2,3,4,5]
def Foo(x):
return x + 1

new_arr = []
for val in (lambda: Foo(x) for x in arr):
new_arr.append(val())

print new_arr

(will print [2,3,4,5,6])
—–

new_arr2 = []
new_arr2.extend((lambda: Foo(x) for x in arr))
new_arr2[0]()
new_arr2[1]()
new_arr2[2]()

(will print 6, 6, 6)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.