Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:two': 0.07; '[1,': 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; 'algorithmic': 0.16; 'hmm.': 0.16; 'low.': 0.16; '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; 'roy': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'meant': 0.20; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'affects': 0.24; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'relative': 0.30; 'subject:list': 0.30; '>>>>': 0.31; 'case,': 0.35; 'but': 0.35; 'subject:?': 0.36; 'skip:o 20': 0.38; '8bit%:86': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'numbers': 0.61; 'costs': 0.63; 'smith': 0.68; 'no:': 0.84; 'ridiculously': 0.84; 'songs': 0.91; 'choice.': 0.93; '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 20:13:18 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p5084907e.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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370974677 news.xs4all.nl 16011 [2001:888:2000:d::a6]:48163 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47692 Chris Angelico wrote: > On Wed, Jun 12, 2013 at 1:28 AM, Serhiy Storchaka > wrote: >> 11.06.13 01:50, Chris Angelico написав(ла): >> >>> On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: >>>> >>>> new_songs = [s for s in songs if s.is_new()] >>>> old_songs = [s for s in songs if not s.is_new()] >>> >>> >>> Hmm. Would this serve? >>> >>> old_songs = songs[:] >>> new_songs = [songs.remove(s) or s for s in songs if s.is_new()] I think you meant old_songs.remove(s). >> O(len(songs)**2) complexity. > > Which isn't significant if len(songs) is low. We weren't told the > relative costs - is the is_new call ridiculously expensive? Everything > affects algorithmic choice. But is it correct? In the general case, no: >>> numbers = [1, 1.0, 2.0, 2] >>> ints = numbers[:] >>> floats = [ints.remove(n) or n for n in numbers if isinstance(n, float)] >>> floats [1.0, 2.0] >>> ints [1.0, 2] # hmm