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


Groups > comp.lang.python > #60159

Re: zip list, variables

From Peter Otten <__peter__@web.de>
Subject Re: zip list, variables
Date 2013-11-21 09:58 +0100
Organization None
References <31cfb6e8-aa7e-46c2-ae0b-18d0d66e7bed@googlegroups.com> <qoteh6bwduh.fsf@ruuvi.it.helsinki.fi> <898792ac-2101-4b92-86e1-f4f9c986de28@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3004.1385024316.18130.python-list@python.org> (permalink)

Show all headers | View raw


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. 

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

zip list, variables flebber <flebber.crue@gmail.com> - 2013-11-20 02:06 -0800
  Re: zip list, variables Peter Otten <__peter__@web.de> - 2013-11-20 11:38 +0100
  Re: zip list, variables Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-11-20 12:45 +0200
    Re: zip list, variables flebber <flebber.crue@gmail.com> - 2013-11-20 12:05 -0800
      Re: zip list, variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-21 01:03 +0000
      Re: zip list, variables Peter Otten <__peter__@web.de> - 2013-11-21 09:58 +0100

csiph-web