|
Current solutions: >>> list(map(partial(pow, exp=3), range(10)))
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
>>> list(map(lambda base: pow(base, 3), range(10)))
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
>>> [pow(base, 3) for base in range(10)]
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
Proposed solution: list(map(bp.partial(pow)(bp._, 3), range(10))
ISTM the only time you come out a little ahead is if you know in advance that a function is going to be partialed (so you can decorate it), that you will need to partial arguments in other than a left to right fashion (otherwise a plain partial will suffice), that you won't use keyword arguments (the current partial works with keywords), and that you really dislike the lambda keyword (which neatly covers all cases from simple to complex without a new notation).That said, this is a clever recipe. Kudos to the author for putting it together. I don't think it really rises to the level of "better" or "more intuitive", but it is an interesting experiment. |
What if you have a function "f" that takes like 10 arguments and you need to pass it to a function "g" that expects as input a function takes 8 arguments.