Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35166 > unrolled thread
| Started by | Chris Kaynor <ckaynor@zindagigames.com> |
|---|---|
| First post | 2012-12-19 09:11 -0800 |
| Last post | 2012-12-19 09:11 -0800 |
| 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.
Re: calculation on lists Chris Kaynor <ckaynor@zindagigames.com> - 2012-12-19 09:11 -0800
| From | Chris Kaynor <ckaynor@zindagigames.com> |
|---|---|
| Date | 2012-12-19 09:11 -0800 |
| Subject | Re: calculation on lists |
| Message-ID | <mailman.1078.1355962816.29569.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Wed, Dec 19, 2012 at 4:38 AM, Vlastimil Brom <vlastimil.brom@gmail.com>wrote: > 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] > >>> > You can also use map (Python 2.6): map(lambda a,b: a+b*a, [1,1,1,1], [5,9,8,4]) Note that the lambda can be replaced by any callable which takes 2 arguments.
Back to top | Article view | comp.lang.python
csiph-web