Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:two': 0.07; '[1,': 0.09; '[],': 0.09; 'naturally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'thrown': 0.09; '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; 'spurious': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'version.': 0.19; 'written': 0.21; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'subject:list': 0.30; "i'm": 0.30; 'code': 0.31; "i'd": 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'subject:?': 0.36; 'should': 0.36; 'turn': 0.37; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'side': 0.67; 'hour': 0.70; 'odds': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Split a list into two parts based on a filter? Date: Tue, 11 Jun 2013 08:43:41 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p5084afc3.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: 1370933017 news.xs4all.nl 15869 [2001:888:2000:d::a6]:46866 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47640 Fábio Santos wrote: > On 10 Jun 2013 23:54, "Roel Schroeven" wrote: >> >> You could do something like: >> >> new_songs, old_songs = [], [] >> [(new_songs if s.is_new() else old_songs).append(s) for s in songs] >> >> But I'm not sure that that's any better than the long version. > > This is so beautiful! It makes me cringe. This code does spurious work to turn what is naturally written as a for loop into a list comprehension that is thrown away immediately. I think I'd even prefer this "gem" >>> evens = [] >>> odds = [item for item in range(10) if item % 2 or evens.append(item)] >>> evens, odds ([0, 2, 4, 6, 8], [1, 3, 5, 7, 9]) but if I have my way every side effect in a list comprehension should be punished with an extra hour of bug-hunting ;)