Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.049 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.01; 'subject:two': 0.07; 'subject:into': 0.09; 'algorithmic': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'low.': 0.16; 'roy': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'affects': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'relative': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'received:209': 0.37; '8bit%:86': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'costs': 0.63; 'smith': 0.68; 'ridiculously': 0.84; 'songs': 0.91; 'choice.': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=v27FPWlgn4VlHE9V69jZ9XR3wlG9U64KyxNsVT3ijY0=; b=VomkYcf5gUjTG3IhvxMSlFD8uxreCB9mh/OTdGp6K3g86Z6bRoCxg9nvdcH/nj1w1C v30opeM60dKCHpvBsssNxlTMUNDdomFtb+7ABRRVUPxw/1YI5ZYolwsFzixxAtaNfPBe fng/ZCY/yghp8x2gYB2du4nzWVTVdgsBUSd+rqlORNAklMfZoKqvZLhRR4mVllzsRsS9 S++jK77XkFNT24/qzsmSkSDEbYLGnjLbP/gGWqeIoKL9nKVpvzN+Ld9J98/MgWlMdyO2 4e3NZtuOTDoapL1oHJsknPEhr3dFNFf5jLtohMCjFLatmVSQ5rTRJ4AwzujDPS3kFl7n OSIA== MIME-Version: 1.0 X-Received: by 10.58.214.105 with SMTP id nz9mr8193521vec.58.1370971714861; Tue, 11 Jun 2013 10:28:34 -0700 (PDT) In-Reply-To: References: Date: Wed, 12 Jun 2013 03:28:34 +1000 Subject: Re: Split a list into two parts based on a filter? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370971724 news.xs4all.nl 15955 [2001:888:2000:d::a6]:50779 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47686 On Wed, Jun 12, 2013 at 1:28 AM, Serhiy Storchaka wro= te: > 11.06.13 01:50, Chris Angelico =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2= (=D0=BB=D0=B0): > >> On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: >>> >>> new_songs =3D [s for s in songs if s.is_new()] >>> old_songs =3D [s for s in songs if not s.is_new()] >> >> >> Hmm. Would this serve? >> >> old_songs =3D songs[:] >> new_songs =3D [songs.remove(s) or s for s in songs if s.is_new()] > > > 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. ChrisA