2 ms·
Well, in Python that would be: from functools import partial square = partial(map, lambda i: i**2) EDIT: I guess it's still not the same, since the lambda
by icebraining 13y ago
Well, in Python that would be:
from functools import partial
square = partial(map, lambda i: i**2)
EDIT: I guess it's still not the same, since the lambda isn't a partial application. But I don't think we can just set the exponent in pow(), we need to create a function that takes the arguments in the reverse order. Maybe:
from functools import wraps, partial
def flip(func):
'Create a new function from the original with the arguments reversed'
@wraps(func)
def newfunc(*args):
return func(*args[::-1])
return newfunc
_pow = flip(pow) #Take Y, then X
# Then the equivalent would be
square = partial(map, partial(_pow, 2)
Of course, flip is rather long-winded because it's a generic function, one could just do:
_pow = lambda y, x: pow(x, y)