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


Groups > comp.lang.python > #35107

Re: calculation on lists

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.083
X-Spam-Evidence '*H*': 0.83; '*S*': 0.00; 'thx': 0.09; 'cc:addr :python-list': 0.10; '>>>': 0.18; 'simpler': 0.22; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'probably': 0.29; 'function': 0.30; 'subject:lists': 0.32; 'cases,': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'tool': 0.36; 'skip:z 10': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'to:charset:iso-8859-1': 0.75; '======': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=w2IvvvZs4hXh8IESdj+9IMZ+eZTKFTsz/WjI5YiPU0Y=; b=wLWXe17R94rOo8U+wvUUWiLcLTyGsshlTJ88pVSaiSmrDVd/WwKWMbJwz+QytCNFU3 fTO43ng2r6h2WOkeWvMq65lalTchz28MIw64yvxQ5d+VMXhAY0wRVefZvzIRruZyGI5V EI2H3Gnst3+tNBI6NRbCciSTTyPRov7dtVrm1L65zKjzHRkh9U0eb7lZRhnEhiaOpHwW QEmc1haOreank61gGqwYNaTnOCk/Qfek95qdQhsmWksSZMSDteg4FQg3QTVlOr0RQ5l6 fVGXH0dpOSvwPIu0wr2e2bawss0FAaXD/Eo4fg//0ZqwTfEsgXHKDGyu49ysrzMuKuPf +p/Q==
MIME-Version 1.0
In-Reply-To <BLU168-W121B52F2829276D9EC909658F300@phx.gbl>
References <BLU168-W121B52F2829276D9EC909658F300@phx.gbl>
Date Wed, 19 Dec 2012 13:38:28 +0100
Subject Re: calculation on lists
From Vlastimil Brom <vlastimil.brom@gmail.com>
To loïc Lauréote <laureote-loic@hotmail.fr>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1045.1355920717.29569.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355920717 news.xs4all.nl 6897 [2001:888:2000:d::a6]:47246
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35107

Show key headers only | 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