Hi,
Short question: why (1,abc,0.3)+(2,def,10.2) != (3,abcdef,10.5)?
How to elegantly achieve (3,abcdef,10.5) as a result of addition ...
Andy
--
http://mail.python.org/mailman/listinfo/python-list
Andy Leszczynski [EMAIL PROTECTED] writes:
Short question: why (1,abc,0.3)+(2,def,10.2) != (3,abcdef,10.5)?
How to elegantly achieve (3,abcdef,10.5) as a result of addition ...
tuple([(a+b) for a,b in zip((1,abc,0.3),(2,def,10.2))])
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin http://[EMAIL PROTECTED] writes:
Andy Leszczynski [EMAIL PROTECTED] writes:
Short question: why (1,abc,0.3)+(2,def,10.2) != (3,abcdef,10.5)?
How to elegantly achieve (3,abcdef,10.5) as a result of addition ...
tuple([(a+b) for a,b in zip((1,abc,0.3),(2,def,10.2))])
Andy Leszczynski [EMAIL PROTECTED] wrote:
Hi,
Short question: why (1,abc,0.3)+(2,def,10.2) != (3,abcdef,10.5)?
Because '+' applied to sequences means to concatenate them -- a more
frequent need than element by element addition (which I notice you
would NOT want to apply to strings, only to
Mike Meyer [EMAIL PROTECTED] writes:
map(operator.add, (1, abc, 0.3), (2, def, 10.2))
[3, 'abcdef', 10.5]
Not having to do the zip is win. operator.add is a lose. I'm not sure
either is what I'd call elegant.
Yeah, I didn't bother checking whether you could pass dyadic functions
to map.
On Mon, 19 Dec 2005 22:06:31 -0500
Andy Leszczynski [EMAIL PROTECTED] wrote:
Short question: why (1,abc,0.3)+(2,def,10.2) !=
(3,abcdef,10.5)?
How to elegantly achieve (3,abcdef,10.5) as a result of
addition ...
(a,b,c) is a tuple, not a vector.
IMHO, the elegant thing to do is to define a