Quantcast
Channel: Currying in Python lambdas - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by LangeHaare for Currying in Python lambdas

$
0
0

This example seems to work for me in python 2.7.11

add = lambda a: lambda b: a + b
f = add(1)
print f(2)
3
print f(10)
11

More complicated examples might fall down though. A lambda function stores references to the variables in the enclosing scope, rather than their values. This might help with a more complicated problem: https://stackoverflow.com/a/938493/8131703


Viewing all articles
Browse latest Browse all 2

Trending Articles