consistency: extending arrays vs. multiplication ?

Dan Bishop danb_83 at yahoo.com
Sat Jul 23 23:25:37 EDT 2005


Soeren Sonnenburg wrote:
> Hi all,
>
> Just having started with python, I feel that simple array operations '*'
> and '+' don't do multiplication/addition but instead extend/join an
> array:
>
> a=[1,2,3]
> >>> b=[4,5,6]
> >>> a+b
> [1, 2, 3, 4, 5, 6]
>
> instead of what I would have expected:
> [5,7,9]

To get what you expected, use

[x + y for (x, y) in zip(a, b)]




More information about the Python-list mailing list