map and operator.add usage

Rainer Deyke root at rainerdeyke.com
Mon Jan 29 17:07:50 EST 2001


"Fernando Rodríguez" <spamers at must.die> wrote in message
news:8okb7t067aicblsjr8idj726hdnt4pn04h at 4ax.com...
> Hi!
>
> In Lisp I can do:
>
> CL-USER 9 > (mapcar #'+ '(1 2) '(3 4) '(5 6))
> (9 12)
>
> but how can I do it in Python?

[reduce(operator.add, l) for l in zip([1, 2], [3, 4], [5, 6])]

...or...

map(lambda l: reduce(operator.add, l), zip([1, 2], [3, 4], [5, 6]))


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list