3 ms·
Python's behavior is the same as Go's. For example, this code: l = [] for i in xrange(3): l.append(lambda: i) print [f() for f in l] prints
by teraflop 10y ago
Python's behavior is the same as Go's. For example, this code:
l = []
for i in xrange(3):
l.append(lambda: i)
print [f() for f in l]
prints [2, 2, 2].
- loevborg 10y agoSame in javascript: var fns=[]; for (var i=0; i<3; i++) { fns.push(function(){return i}); }; fns.map(function(x) { return x.call(); }); Returns [ 3, 3, 3 ]