Hello,

I am still fairly new to Python. Can someone explain to me why there
is a difference in f and g:

def make_power(n):
    return lambda x: x ** n

# Create a set of exponential functions
f = [lambda x: x ** n for n in xrange(2, 5)]
g = [make_power(n) for n in xrange(2, 5)]

print f[0](3), f[1](3)
print g[0](3), g[1](3)


I expect to have "f" act same like "g".

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to