I need to store functions in a dictionary, each function depending on its key, lets say, for a key 1
the lambda function associated is lambda s: s * A[1]
. I tried with dict comprehension but it seems that the inline functions ends defined with the last value of the loop.
d = {k, lambda s: s * A[k] for k in range(n)} # e.g. n = 4
After that all lambda functions created are declared with A[3]
instead of A[0], A[1], A[2]
and A[3]
. What's wrong with this code?