Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '(python': 0.05; 'callable': 0.09; 'thx': 0.09; 'cc:addr:python-list': 0.10; 'dec': 0.15; 'lambda': 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'email addr:gmail.com>': 0.20; '>>>': 0.22; 'simpler': 0.22; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'arguments.': 0.29; 'skip:& 10': 0.29; 'probably': 0.29; 'function': 0.30; 'subject:lists': 0.32; 'cases,': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'replaced': 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; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'takes': 0.39; 'header:Received:5': 0.40; 'map': 0.61; '\xa0have': 0.84; '======': 0.91 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:x-gm-message-state; bh=mmDXvs3YBOgyuSL9DBCXAMsxEkGYP7MREACqFp/gp0w=; b=HdVJnyVX/Nz/hRqRahjBepXFVK4iSJ/xJxZNsfB3BMncdsLlHbniwfqveB5MoFRGPc eeD2LEAHWAJ2QHVnQMJoTAIcv6dvgQvxVHLX8iUByQGhc/IHBjefwFB1kVMBjwj+HTKT JDTEM3VemlRRv1mdKQcAryyHoxCHh6NDe43GDQqGSZdbecyg9iRlvBn3wdN94jft367h 9x4CBRKEi+FNEoROlmaU4YgQyYFRYRbZBAbp8fy+TaJ+yWq+J3ix3CraFrPwusS6fxqX MKLIAkhQfhmRc0yUiOHvMDB+Ym1YMzEK0jhKCbx2m7CEWPXhQX3jbxDY7Rc2nYNZJgtT 0Usw== MIME-Version: 1.0 In-Reply-To: References: From: Chris Kaynor Date: Wed, 19 Dec 2012 09:11:14 -0800 Subject: Re: calculation on lists To: Vlastimil Brom Content-Type: multipart/alternative; boundary=20cf30334ecb84818404d13db113 X-Gm-Message-State: ALoCoQkrDS9r9VFsyU0VT0Y1HC7kdRq7voS0iMl42xcd9Aj/o3gTEBP/XIksWZuS9NLMU87BUMiA Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355962816 news.xs4all.nl 6909 [2001:888:2000:d::a6]:50994 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35166 --20cf30334ecb84818404d13db113 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Dec 19, 2012 at 4:38 AM, Vlastimil Brom w= rote: > 2012/12/19 lo=EFc Laur=E9ote : > hi, > I > have a question, > is there a tool to calculate on list ? > > something like : > > >a=3D [1,1,1,1] > >b =3D [5,9,8,4] > >c =3D a+b*a > >print c > >[6,10,9,5] > > Thx > > =3D=3D=3D=3D=3D=3D > > 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. --20cf30334ecb84818404d13db113 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Wed, Dec 19, 2012 at 4:38 AM, Vlastimil Brom <= vlastimil.brom@gmail.com> wrote:
2012/12/19 lo=EFc Laur=E9ote <laureote-loic@hotmail.fr>:
hi,
I
=A0have a question,
is there a tool to calculate on list ?

something like :

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

Thx

=3D=3D=3D=3D=3D=3D

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 repla= ced by any callable which takes 2 arguments.
--20cf30334ecb84818404d13db113--