Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47614
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.034 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'url:pypi': 0.03; 'else:': 0.03; 'subject:two': 0.07; 'similar,': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'expecting': 0.16; 'itertools': 0.16; 'roy': 0.16; 'sorting': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'fit': 0.20; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'module,': 0.24; 'passes': 0.24; 'requirement.': 0.24; 'mon,': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; "doesn't": 0.30; 'compared': 0.30; 'raymond': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'lines': 0.31; 'this.': 0.32; 'url:python': 0.33; 'maybe': 0.34; 'could': 0.34; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'two': 0.37; 'list.': 0.37; 'list,': 0.38; 'pm,': 0.38; 'does': 0.39; 'bill': 0.39; 'enough': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'such': 0.63; 'skip:n 10': 0.64; 'due': 0.66; 'of:': 0.68; 'smith': 0.68; 'groups.': 0.74; 'divide': 0.84; 'sender:addr:chris': 0.84; 'want:': 0.84; 'do:': 0.91; 'songs': 0.91; 'songs,': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=dDlmqxHnG8aA7/dZIQox+an8yqgoJXpNpZjRi90ayro=; b=Jx4c3hLjFYtU3BBG8Dv5uryyLmQB6EKy7LaJjMXFN8jUEaZNCOj0K/SBw43KKIba8P reimkh7UxijHX6xKTpgXnBc2SfGEx8+jm/HfeFehXzywIih7div4JPPqjvxasIe83bQz 8zR9zK1d5jjRGbOjZsmWRLs5OUk/ciJw+JXrs= |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=dDlmqxHnG8aA7/dZIQox+an8yqgoJXpNpZjRi90ayro=; b=olbXqlVGF8jCoBHv3qeFBNnefJ/5zrmk8EgVnJVtJF3OliCts/FkGEEfZYKS0BiEx9 lVNUgP7row6VPLHZllqRNo1n//KIxNjWSqhmNe5PZjnPiH/em4pKvm+fwdnQOnXF/nl2 bSPiUOpVTwZC8xNNj38q+vSyuXFiEPAIh44Qm/IAOgnHBeyM+RKBY+wf8QAqkV+J99ok cOLpEja2qiiGXza3fTwTwUbwmqeGuxS6XCdlyyScZypOMbfrReIufl7WAXEaS1tBbxmt 9CmwucnSGKGFYRY9GvuNKXuBrhn7o60Ir/BHO4dKPsxiXyzn+hmdkvWbJT0P+LLnOXg3 EwdQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.118.97 with SMTP id kl1mr4804503igb.46.1370905422931; Mon, 10 Jun 2013 16:03:42 -0700 (PDT) |
| Sender | chris@rebertia.com |
| In-Reply-To | <kp5d9e$2hf$1@panix2.panix.com> |
| References | <kp5d9e$2hf$1@panix2.panix.com> |
| Date | Mon, 10 Jun 2013 16:03:42 -0700 |
| X-Google-Sender-Auth | tVMz-hLbamBfCLfzYt3s7wa47yA |
| Subject | Re: Split a list into two parts based on a filter? |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Roy Smith <roy@panix.com> |
| Content-Type | text/plain; charset=UTF-8 |
| X-Gm-Message-State | ALoCoQnqtfm9LTmdb4LHK4PCt51J1AZQX1JOf/cEF0Zp8rvTAkU1Y1f4l3rmLM17hVedRGOjQF22 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2994.1370905425.3114.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370905425 news.xs4all.nl 15911 [2001:888:2000:d::a6]:59955 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47614 |
Show key headers only | View raw
On Mon, Jun 10, 2013 at 1:34 PM, Roy Smith <roy@panix.com> wrote: > I have a list, songs, which I want to divide into two groups. > Essentially, I want: > > new_songs = [s for s in songs if s.is_new()] > old_songs = [s for s in songs if not s.is_new()] > > but I don't want to make two passes over the list. I could do: > > new_songs = [] > old_songs = [] > for s in songs: > if s.is_new(): > new_songs.append(s) > else: > old_songs.append(s) > > Which works, but is klunky compared to the two-liner above. This > seems like a common enough thing that I was expecting to find > something in itertools which did this. I'm thinking something along > the lines of: > > matches, non_matches = isplit(lambda s: s.is_new, songs) > > Does such a thing exist? itertools.groupby() is kinda similar, but unfortunately doesn't fit the bill due to its sorting requirement. There is regrettably no itertools.partition(). And given how dead-set Raymond seems to be against adding things to the itertools module, there will likely never be. Maybe more-itertools (https://pypi.python.org/pypi/more-itertools ) would accept a patch? Cheers, Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Split a list into two parts based on a filter? roy@panix.com (Roy Smith) - 2013-06-10 16:34 -0400
Re: Split a list into two parts based on a filter? Chris Angelico <rosuav@gmail.com> - 2013-06-11 08:50 +1000
Re: Split a list into two parts based on a filter? Roel Schroeven <roel@roelschroeven.net> - 2013-06-11 00:50 +0200
Re: Split a list into two parts based on a filter? Roy Smith <roy@panix.com> - 2013-06-11 00:11 -0400
Re: Split a list into two parts based on a filter? Serhiy Storchaka <storchaka@gmail.com> - 2013-06-11 18:27 +0300
Re: Split a list into two parts based on a filter? Roy Smith <roy@panix.com> - 2013-06-11 20:33 -0400
Re: Split a list into two parts based on a filter? Phil Connell <pconnell@gmail.com> - 2013-06-12 07:32 +0100
Re: Split a list into two parts based on a filter? Roy Smith <roy@panix.com> - 2013-06-12 07:39 -0400
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-12 12:51 +0100
Re: Split a list into two parts based on a filter? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-06-12 15:06 +0300
Re: Split a list into two parts based on a filter? Terry Reedy <tjreedy@udel.edu> - 2013-06-12 14:07 -0400
Re: Split a list into two parts based on a filter? Serhiy Storchaka <storchaka@gmail.com> - 2013-06-12 19:28 +0300
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-12 17:57 +0100
Re: Split a list into two parts based on a filter? Terry Reedy <tjreedy@udel.edu> - 2013-06-12 14:47 -0400
Re: Split a list into two parts based on a filter? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-06-13 10:43 +0100
Re: Split a list into two parts based on a filter? Chris Rebert <clp2@rebertia.com> - 2013-06-10 16:03 -0700
Re: Split a list into two parts based on a filter? Tim Chase <python.list@tim.thechases.com> - 2013-06-10 18:10 -0500
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-11 00:08 +0100
Re: Split a list into two parts based on a filter? alex23 <wuwei23@gmail.com> - 2013-06-11 17:44 -0700
Re: Split a list into two parts based on a filter? Chris Angelico <rosuav@gmail.com> - 2013-06-11 09:12 +1000
Re: Split a list into two parts based on a filter? Peter Otten <__peter__@web.de> - 2013-06-11 02:11 +0200
Re: Split a list into two parts based on a filter? Peter Otten <__peter__@web.de> - 2013-06-11 08:43 +0200
Re: Split a list into two parts based on a filter? Jonas Geiregat <jonas@geiregat.org> - 2013-06-11 08:47 +0200
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-11 14:48 +0100
Re: Split a list into two parts based on a filter? rusi <rustompmody@gmail.com> - 2013-06-11 09:37 -0700
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-11 18:05 +0100
Re: Split a list into two parts based on a filter? rusi <rustompmody@gmail.com> - 2013-06-11 10:23 -0700
Re: Split a list into two parts based on a filter? Chris Angelico <rosuav@gmail.com> - 2013-06-12 03:37 +1000
Re: Split a list into two parts based on a filter? rusi <rustompmody@gmail.com> - 2013-06-11 11:13 -0700
Re: Split a list into two parts based on a filter? Fábio Santos <fabiosantosart@gmail.com> - 2013-06-11 19:05 +0100
Re: Split a list into two parts based on a filter? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-11 15:22 +0100
Re: Split a list into two parts based on a filter? Serhiy Storchaka <storchaka@gmail.com> - 2013-06-11 18:28 +0300
Re: Split a list into two parts based on a filter? Chris Angelico <rosuav@gmail.com> - 2013-06-12 03:28 +1000
Re: Split a list into two parts based on a filter? Roy Smith <roy@panix.com> - 2013-06-11 20:12 -0400
Re: Split a list into two parts based on a filter? Peter Otten <__peter__@web.de> - 2013-06-11 20:13 +0200
Re: Split a list into two parts based on a filter? Peter Otten <__peter__@web.de> - 2013-06-11 20:18 +0200
Re: Split a list into two parts based on a filter? Chris Angelico <rosuav@gmail.com> - 2013-06-12 04:27 +1000
Re: Split a list into two parts based on a filter? Roel Schroeven <roel@roelschroeven.net> - 2013-06-11 22:22 +0200
csiph-web