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


Groups > comp.lang.python > #31497

Re: list comprehension question

Date 2012-10-17 08:32 -0400
From Dave Angel <d@davea.name>
Subject Re: list comprehension question
References <CA+C4C6f=24oD4seHY_-h1F0GMvBTWNYbzTABXOdtKkAZtE9hdQ@mail.gmail.com> <507E145E.9060008@davea.name> <CA+C4C6cjha4bMZ9gyx5fTp0c_nfFQxRGu31dGNMjgHQBu73=ig@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2341.1350477185.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/17/2012 12:43 AM, Kevin Anthony wrote:
> Is it not true that list comprehension is much faster the the for loops?
> 
> If it is not the correct way of doing this, i appoligize.
> Like i said, I'm learing list comprehension.
> 
(Please don't top-post;  it ruins the ordering.  In these forums, put
your response after the part you quote from earlier messages.  Or even
better, after each part you quote.  Then trim off the parts you didn't
reference.)

list comprehensions CAN be much faster, but not necessarily.  The most
complex a loop, the less likely it'll help much.

In any case, only the inner loop will be affected.  Nesting two list
comprehensions will make a trivial difference.

On the other hand, Hans Mulder shows some other factoring which seems
much more readable than yours.

Studying (and testing) those could teach you a lot about comprehensions,
as well as about the libraries that can help.  Note especially what
zip(*b) yields, and think about what it means.


-- 

DaveA

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


Thread

Re: list comprehension question Dave Angel <d@davea.name> - 2012-10-17 08:32 -0400
  Re: list comprehension question rusi <rustompmody@gmail.com> - 2012-10-17 07:06 -0700
    Re: list comprehension question rusi <rustompmody@gmail.com> - 2012-10-17 07:33 -0700
    Re: list comprehension question Dave Angel <d@davea.name> - 2012-10-17 10:36 -0400
      Re: list comprehension question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-17 07:45 -0700
      Re: list comprehension question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-17 07:45 -0700
      Re: list comprehension question rusi <rustompmody@gmail.com> - 2012-10-17 07:50 -0700
        Re: list comprehension question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-17 08:06 -0700

csiph-web