I have some lamdba
functions as values in a dictionary. I would like to create new dictionary from the existing one that has lambdas derived from the values in the first. However, I am getting weird pointer behavior when I do this: all the composed lambda
functions in the second dictionary point to its last entry.
base_checks = {'big': lambda x: x > 10, 'small': lambda x: x < 0.01}
fancy_checks = {name: lambda x: base_checks[name](x) for name in ['big', 'small']}
I wrote some example code above to describe this behavior. The function fancy_checks['big']
is supposed to point to base_checks['big']
but it actually points to the function base_checks['small']
.