Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'sufficient': 0.05; 'nested': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'wondering': 0.29; 'subject:list': 0.30; 'lists': 0.32; 'moment': 0.34; 'but': 0.35; 'replies': 0.36; 'should': 0.36; 'list': 0.37; 'easily': 0.37; 'thank': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'more': 0.64; 'more?': 0.84; 'replies.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: zip list, variables Date: Thu, 21 Nov 2013 09:58:54 +0100 Organization: None References: <31cfb6e8-aa7e-46c2-ae0b-18d0d66e7bed@googlegroups.com> <898792ac-2101-4b92-86e1-f4f9c986de28@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a6c3.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385024316 news.xs4all.nl 15926 [2001:888:2000:d::a6]:34407 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60159 flebber wrote: > Thank you for the replies. > > Looking at the replies I am wondering which solution is more scalable. At > the moment it is only 2 nested lists but what about 5, 10, 20 or more? > > Should I start looking into numpy to handle this or will list > comprehension > >>> [ [ x + y for x, y in zip(x,y) ] for x, y in zip(a,b) ] > Be sufficient ? I would certainly prefer >>> a + b array([[ 6, 8], [10, 12]]) over the incomprehensible comprehension. But if it is the only usecase for numpy in your script and you are OK with its current performance, just put your listcomp into an aptly named function. Then you can write the easily understandable c = matrix_add(a, b) and avoid the numpy dependency.