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?
Check out itertools for tools that will make your life easier.
For example, the code you posted is already available as
itertools.starmap.From the documentation:
There are also tons over other goodies hidden in
itertools, so I recommend you read through the documentation to see if there is anything else there that you can use. The recipes section also show ways that you can use the functions available initertoolsto solve a variety of problems. Even if you can’t find a recipe that solves your exact requirements, it’s likely that you can use some of the ideas demonstrated as a source of inspiration.