Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.055 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'messages.': 0.04; 'subject:skip:c 10': 0.07; 'subject:question': 0.08; 'cc:addr :python-list': 0.10; 'means.': 0.16; 'nesting': 0.16; 'readable': 0.16; 'wrote:': 0.17; 'earlier': 0.21; 'libraries': 0.22; 'help.': 0.22; 'cc:2**0': 0.23; 'kevin': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'correct': 0.28; 'subject:list': 0.28; 'faster,': 0.29; 'loop,': 0.29; 'case,': 0.29; "i'm": 0.29; '(and': 0.32; 'could': 0.32; 'much.': 0.33; 'likely': 0.33; 'list': 0.35; 'faster': 0.35; 'said,': 0.35; 'especially': 0.35; 'doing': 0.35; 'but': 0.36; "didn't": 0.36; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'shows': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'more': 0.63; 'header :Reply-To:1': 0.68; 'teach': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'difference.': 0.84; 'affected.': 0.91; 'yours.': 0.93; 'hand,': 0.97 Date: Wed, 17 Oct 2012 08:32:43 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Kevin Anthony Subject: Re: list comprehension question References: <507E145E.9060008@davea.name> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:pHAPeVShOUizAS40uu+A6xUPA1k19V7Z9oK6MFp4WEx lo4AOY6SjpbXDva5me64j2osAEAEIOsv4t+uqrXFVLN5Nvgia2 yS/JGQcTt5XILetTS3FYliogdnPxcPSVaxhMbkiz5aBhxPLqPE AFEv5TSITutfBOM5Vrqk7NKKn9Lb2rYOduVuJcySAwz7tQs9vC GBiOSeWk/LsHrRVtJhqpE6MbWy1ZBueQXdM/KF1Ml3vP1UialV kqS2lQgekuozwakLe/Ua1X09jZEnk/hqUi9mX8itzmFIvdWj2q zh8xhQt40zIXyVla1Uvd4y7XdvS6DCtRjXOOqtHwan7FDSJxg= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: d@davea.name 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350477185 news.xs4all.nl 6968 [2001:888:2000:d::a6]:44097 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31497 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