Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'languages.': 0.04; 'subject:two': 0.07; 'agrees': 0.09; 'implements': 0.09; 'indeed,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'subject:into': 0.09; 'python': 0.11; 'jan': 0.12; 'collections': 0.16; 'conditional': 0.16; 'exactly,': 0.16; 'hack,': 0.16; 'loops': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'roy': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'example': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'possibly': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'wonder': 0.29; 'subject:list': 0.30; 'concern': 0.31; 'another': 0.32; 'subject:?': 0.36; 'turn': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'lists.': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'everybody': 0.60; 'no.': 0.61; 'received:173': 0.61; 'map': 0.64; 'more': 0.64; 'smith': 0.68; 'abuse.': 0.84; 'expresses': 0.84; 'received:fios.verizon.net': 0.84; 'seriously,': 0.84; 'song': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Split a list into two parts based on a filter? Date: Wed, 12 Jun 2013 14:07:49 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371060481 news.xs4all.nl 15994 [2001:888:2000:d::a6]:47665 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47828 On 6/12/2013 7:39 AM, Roy Smith wrote: > starts. But, somewhat more seriously, I wonder what, exactly, it is > that freaks people out about: > >>>>> [(new_songs if s.is_new() else old_songs).append(s) for s in songs] > > Clearly, it's not the fact that it build and immediately discards a > list, because that concern is addressed with the generator hack, and I > think everybody (myself included) agrees that's just horrible. It is an example of comprehension abuse. Comprehensions express and condense a stylized pattern of creating collections from another collection or collections, possibly filtered. They were not mean to replace for statements and turn Python into an fp languages. Indeed, they do replace and expand upon the fp map function. Python for loops are not evil. > Or, is it the use of the conditional to create the target for append()? > Would people be as horrified if I wrote: > > for s in songs: > (new_songs if s.is_new() else old_songs).append(s) No. That succinctly expresses and implements the idea 'append each song to one of two lists. > or even: > > for s in songs: > the_right_list = new_songs if s.is_new() else old_songs > the_right_list.append(s) > -- Terry Jan Reedy