list*list
Tim Williams
tdwdotnet at gmail.com
Mon May 1 11:43:27 EDT 2006
On 1 May 2006 08:28:12 -0700, BBands <bbands at gmail.com> wrote:
>
> There must be a better way to multiply the elements of one list by
> another:
>
> a = [1,2,3]
> b = [1,2,3]
> c = []
> for i in range(len(a)):
> c.append(a[i]*b[i])
> a = c
> print a
> [1, 4, 9]
>
>
Something like:
>>> [ x * y for x,y in zip(a,b) ]
[1, 4, 9]
:)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060501/79e5fb25/attachment.html>
More information about the Python-list
mailing list