map
and filter
are often interchangeable with list comprehensions, but reduce
is not so easily swapped out as map
and filter
(and besides, in some cases I still prefer the functional syntax anyway). When you need to operate on the arguments themselves, though, I find myself going through syntactical gymnastics and eventually have to write entire functions to maintain readability.
I'll use map
to keep the illustration unit-test simple, but please keep in mind that real-life use-cases might be harder to express as a list comprehension.
I've found two messy ways to go about it, but nothing I would ever actually use.
[afunc(*i) for i in aniter] == map(afunc, *zip(*aniter))
[afunc(*i) for i in aniter] == map(lambda i: apply(afunc, i), aniter)
Is there any pithy, elegant way to express the right hand side of these expressions?