2 ms·
Yeah... so I agree that's confusing. It's akin to: def x(y=[]): y.append(1) return y for z in range(4): print x() For your c
by bb88 10y ago
Yeah... so I agree that's confusing. It's akin to:
def x(y=[]):
y.append(1)
return y
for z in range(4):
print x()
For your case, I recommend using partial functions, which were created for this type of issue. I think it's also cleaner than closures where x depends on an outside context.