4 ms·
This is missing an extremely difficult to grasp thing - namespaces and binding. https://docs.python.org/3/reference/executionmodel.html#naming-and-binding https
by svilen_dobrev 8y ago
This is missing an extremely difficult to grasp thing - namespaces and binding. https://docs.python.org/3/reference/executionmodel.html#naming-and-binding https://docs.python.org/3/reference/executionmodel.html#nami...
#example:
scalers = {}
for k in range(1,55):
scalers[k] = lambda x: x*k
print( scaler[2](3))
#Above does not work, or worse, sometimes it may work..
#eo-example
And without it, it's all just another procedural indents-instead-of-brackets thingie
- Doxin 8y agoJust doublechecking to make sure I get it, the solution there is to replace the lambda with something like this right?: lambda x, k=k: x*k