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


Groups > comp.lang.python > #35107 > unrolled thread

Re: calculation on lists

Started byVlastimil Brom <vlastimil.brom@gmail.com>
First post2012-12-19 13:38 +0100
Last post2012-12-19 13:38 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#35107 — Re: calculation on lists

FromVlastimil Brom <vlastimil.brom@gmail.com>
Date2012-12-19 13:38 +0100
SubjectRe: calculation on lists
Message-ID<mailman.1045.1355920717.29569.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web