cyril.bazin at gmail.com
Fri Aug 5 01:07:34 CEST 2005
I propose 3 solutions. If someone have time to waste, he can make a
benchmark to know which is the fastest and give us the results on the list.
c = [a_i-b_i for a_i, b_i in itertools.izip(a, b)]
c = map(operator.sub, a, b)
#"map" will be removed from the next versions of python. So, it's not a good
c = list(itertools.imap(operator.sub, a, b))
These solutions give you a list. Depending on your usage, an iterator can be
On 04 Aug 2005 15:41:28 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>
> "Terrance N. Phillip" <mediocre_person at hotmail.com> writes:
> > Given a and b, two equal length lists of integers, I want c to be
> > [a1-b1, a2-b2, ... , an-bn].
> c = [a[i] - b[i] for i in xrange(len(a))]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list