1
How to get the result, not a link to memory (python)
ChapeauClaque (0)
squares = []
for x in range(5):
    squares.append(lambda x : x**2)
print (list(squares))

Result: [<function <lambda> at 0x7f87461dee18>, <function <lambda> at 0x7f87419b40d0>, <function <lambda> at 0x7f87419b4158>, <function <lambda> at 0x7f87419b41e0>, <function <lambda> at 0x7f87419b4268>]
Tell me, please, how to get a list of function results

You are viewing a single comment. View All
1
leon332157 (55)

@ChapeauClaque You are appending the lambda object instead of the result because in Python everything is an object. So if you want to get the result, u have to call the function, can be done with squares.append((lambda x : x**2)(x)).