my favorite line of py code so far

Paul Rubin no.email at nospam.invalid
Sat Nov 9 04:49:28 EST 2013


Peter Cacioppi <peter.cacioppi at gmail.com> writes:
>>>> [P(*args) for args in zip([1,2,3], [6, 5, 4])] 
[P(x,y) for x,y in zip(...)]

> Are you saying it's always preferable to avoid map?

Not always.  Depends on context, partly subjective.

> I sometimes use map, sometimes comprehensions. I suspect other people
> do the same, that's why the language supports map and comprehensions.

Comprehensions came along later and there was some noise made about
eliminating map for a while, though I think that's died down.

> "there is also itertools.starmap(): "
> Thanks, that's a bit closer to what I am doing.  To me the pure
> combinator is more appealing than starmap, 

You could look at the functools module too, particularly
functools.partial.  For that matter, you could also try Haskell.  It's
even more concise, and this flavor of code is easier to keep reliable
when there's compile-time type checking.



More information about the Python-list mailing list