Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35107

Re: calculation on lists

References <BLU168-W121B52F2829276D9EC909658F300@phx.gbl>
Date 2012-12-19 13:38 +0100
Subject Re: calculation on lists
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1045.1355920717.29569.python-list@python.org> (permalink)

Show all headers | View raw


2012/12/19 loïc Lauréote <laureote-loic@hotmail.fr>:
hi,
I
 have a question,
is there a tool to calculate on list ?

something like :

>a= [1,1,1,1]
>b = [5,9,8,4]
>c = a+b*a
>print c
>[6,10,9,5]

Thx

======

Hi,
for such simpler cases, you may try list comprehensions and probably
the zip(...) function

>>> [a+b*a for a,b in zip([1,1,1,1], [5,9,8,4])]
[6, 10, 9, 5]
>>>

hth,
  vbr

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: calculation on lists Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-19 13:38 +0100

csiph-web