Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:two': 0.07; '[],': 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; 'wrote': 0.14; 'creates': 0.14; 'agree.': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 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; 'header:In- Reply-To:1': 0.27; 'subject:list': 0.30; "i'm": 0.30; 'code': 0.31; 'away.': 0.31; 'pascal': 0.31; 'could': 0.34; 'something': 0.35; 'received:84': 0.35; 'but': 0.35; 'subject:?': 0.36; 'turn': 0.37; 'two': 0.37; 'list': 0.37; 'clear': 0.37; 'skip:o 20': 0.38; 'problems': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'real': 0.63; 'otten': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Roel Schroeven Subject: Re: Split a list into two parts based on a filter? Date: Tue, 11 Jun 2013 22:22:53 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: d54c6d802.access.telenet.be User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) In-Reply-To: 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370982186 news.xs4all.nl 16000 [2001:888:2000:d::a6]:35161 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47702 Peter Otten schreef: > 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 agree. I see two problems with it: it's not very readable or pythonic, and it creates a list that is not needed and is immediately thrown away. I wrote that code just to see if I could make it work that way. In real code I would never write it that way, let's make that clear :) -- "People almost invariably arrive at their beliefs not on the basis of proof but on the basis of what they find attractive." -- Pascal Blaise roel@roelschroeven.net