my favorite line of py code so far
peter.cacioppi at gmail.com
Sat Nov 9 10:23:20 CET 2013
Peter Otten said:
">>> _ = lambda c: lambda x: c(*x)
>>> list(map(_(P), zip([1,2,3], [6, 5, 4])))
[Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)]
? While the obvious approach would be
>>> [P(*args) for args in zip([1,2,3], [6, 5, 4])]
[Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)] "
I would have coded
>>> map(_(P), zip([1,2,3], [6, 5, 4]))
Which is very concise and (to me) quite clear. Forgive me for having a bias for fewer characters.
Are you saying it's always preferable to avoid map? Is map going to be deprecated?
I sometimes use map, sometimes comprehensions. I suspect other people do the same, that's why the language supports map and comprehensions.
"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, but the presence of starmap explains why the library wouldn't need the combinator.
More information about the Python-list