Re:Asterisks in Python
by nemetroid on Thursday October 11, 2018 @07:30PM
(#18197874)
I think the star syntax is a lot nicer than `apply`. Python actually had an `apply` builtin, but it was deprecated in Python 2.3.
[ Parent
| on HN ]
Apply, and first class / higher order functions in general are good in languages where they compose well. Python's * won't compose well.
Re:Asterisks in Python
by quietbritishjim on Friday October 12, 2018 @01:00PM
(#18202819)
To add a small footnote to the existing replies to this comment: A related, but slightly different, function in the `functools` module (part of the Python standard library) is the `partial` function. It is like apply() but returns a function instead of calling the function and return its return value:
f1 = partial(f, 1, 2)
f2 = partial(f1, 3, 4)
f2(5, 6) # equivalent to f(1, 2, 3, 4, 5, 6)
It also supports kwargs. def apply(f, a):
return f(*a)