Id like to define a list of functions by a list of parameters, to actually compose a potential from a finite number of monopoles and dipoles.
Functions in python list, however, for some reason do not behave as expected (by me).
The following example:
def function(coefficients):
phi = []
i = 0
for y in coefficients:
f = lambda x: y*(x**i)
i += 1
phi.append(f)
print f(2)
return phi
> phi = function([1,2,3])
2
8
24
> k0 = phi[0]
> k1 = phi[1]
> k2 = phi[2]
> print k0(2), k1(2), k2(2)
24 24 24
Always the last function in the list is retrieved independent of which function is picked from the list.
Any ideas?
Thanks in advance.