Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34248

Re: Good use for itertools.dropwhile and itertools.takewhile

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'case.': 0.05; '&quot;': 0.09; '&quot;)': 0.09; 'posting.': 0.09; 'yeah,': 0.09; 'def': 0.10; 'thread': 0.11; 'index': 0.13; 'dec': 0.15; 'alexander': 0.16; 'empty.': 0.16; 'indexerror:': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; 'supposed': 0.21; '"",': 0.22; '&gt;&gt;&gt;': 0.22; 'subject:skip:i 10': 0.22; '&gt;': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; '(most': 0.27; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'post': 0.28; '>>>>': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'received:209.85.215.46': 0.30; 'file': 0.32; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'fail': 0.35; 'received:209.85': 0.35; 'skip:p 20': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'range': 0.60; 'saw': 0.75; 'to:name:python': 0.84; 'you;': 0.84; 'subject:Good': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=1fp3EqUM+lqTHTOB2dtEloSWjG6pi68MCeEjxfL5qCM=; b=QjTENJMuxpCuubNGJcci1tNaKhgSaytfnDsLTzPXm3fDXjVsO5I1DkmBvFLejoVLAS uMZD9ogZ5jv0c8m5M92QVenbxl0dLfaKJ9gff0pzvvGhfGc04dnX3h0j99opuOnMr14c zEMohCNm1lbOdOhSxS9ybL5AiFpDtp6D0V+ZFfCCvUJEsBLwNEIePaBoiihZ87IU0+BI Yt2P+Cezz7LIYTw8yWriwI4ntHUYJSvtv2c3GpKaJR4LdDtoDQcg7PQ8I/F0Pkygq/n7 Vqfe3bFbd7IAgNbgPxow0XaovnP/TUJU6gJYp4ml5tSEh2kfA7vpTFmttNBYMMMTganS ownA==
MIME-Version 1.0
In-Reply-To <50be4566$0$9507$9b4e6d93@newsspool1.arcor-online.net>
References <b80f3ab3-ef81-4806-86db-efd5800d4bb3@googlegroups.com> <50be3049$0$9517$9b4e6d93@newsspool1.arcor-online.net> <k9lfd0$evp$1@dont-email.me> <50be4566$0$9507$9b4e6d93@newsspool1.arcor-online.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 4 Dec 2012 12:37:38 -0700
Subject Re: Good use for itertools.dropwhile and itertools.takewhile
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=bcaec55404986bf7cb04d00c01ce
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.470.1354649891.29569.python-list@python.org> (permalink)
Lines 85
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354649891 news.xs4all.nl 6961 [2001:888:2000:d::a6]:53971
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34248

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinne <news@blinne.net> wrote:

> Am 04.12.2012 19:28, schrieb DJC:
> >>>> (i for i,v in enumerate(w) if v.upper() != v).next()
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > AttributeError: 'generator' object has no attribute 'next'
>
> Yeah, i saw this problem right after i sent the posting. It now is
> supposed to read like this
>
> >>> def split_product(p):
> ...     w = p.split(" ")
> ...     j = next(i for i,v in enumerate(w) if v.upper() != v)
> ...     return " ".join(w[:j]), " ".join(w[j:])
>

It still fails if the product description is empty.

>>> split_product("CAPSICUM RED")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in split_product
StopIteration

I'm not meaning to pick on you; some of the other solutions in this thread
also fail in that case.

>>> re.findall(r"(?m)^([A-Z\s]+) (.+)$", "CAPSICUM RED")
[('CAPSICUM', 'RED')]

>>> prod_desc("CAPSICUM RED")  # the second version from Neil's post
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 14, in prod_desc
IndexError: string index out of range

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 05:57 -0800
  Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-04 14:23 +0000
    Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 06:47 -0800
      Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-04 15:17 +0000
  Re: Good use for itertools.dropwhile and itertools.takewhile Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-04 15:31 +0100
    Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 07:24 -0800
      Re: Good use for itertools.dropwhile and itertools.takewhile Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-04 22:08 +0100
    Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 07:24 -0800
      Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-04 18:26 +0000
  Re: Good use for itertools.dropwhile and itertools.takewhile Alexander Blinne <news@blinne.net> - 2012-12-04 18:18 +0100
    Re: Good use for itertools.dropwhile and itertools.takewhile DJC <djc@news.invalid> - 2012-12-04 18:28 +0000
      Re: Good use for itertools.dropwhile and itertools.takewhile Alexander Blinne <news@blinne.net> - 2012-12-04 19:48 +0100
        Re: Good use for itertools.dropwhile and itertools.takewhile Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-04 12:37 -0700
          Re: Good use for itertools.dropwhile and itertools.takewhile Alexander Blinne <news@blinne.net> - 2012-12-04 21:33 +0100
          Re: Good use for itertools.dropwhile and itertools.takewhile Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-04 21:13 +0000
        Re: Good use for itertools.dropwhile and itertools.takewhile MRAB <python@mrabarnett.plus.com> - 2012-12-04 20:17 +0000
  Re: Good use for itertools.dropwhile and itertools.takewhile Terry Reedy <tjreedy@udel.edu> - 2012-12-04 15:44 -0500
    Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 17:17 -0800
      Re: Good use for itertools.dropwhile and itertools.takewhile Chris Angelico <rosuav@gmail.com> - 2012-12-06 00:45 +1100
        Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-05 14:34 +0000
          Re: Good use for itertools.dropwhile and itertools.takewhile Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-05 08:33 -0700
            Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-05 16:11 +0000
      Re: Good use for itertools.dropwhile and itertools.takewhile Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-12-05 15:32 +0000
      Re: Good use for itertools.dropwhile and itertools.takewhile Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-05 09:16 -0700
      Re: Good use for itertools.dropwhile and itertools.takewhile MRAB <python@mrabarnett.plus.com> - 2012-12-05 17:57 +0000
    Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-04 17:17 -0800
      Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-05 13:29 +0000
        Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-05 09:04 -0800
          Re: Good use for itertools.dropwhile and itertools.takewhile MRAB <python@mrabarnett.plus.com> - 2012-12-05 17:57 +0000
          Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-05 18:16 +0000
            Re: Good use for itertools.dropwhile and itertools.takewhile Nick Mellor <thebalancepro@gmail.com> - 2012-12-05 11:01 -0800
              Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-05 20:13 +0000
              Re: Good use for itertools.dropwhile and itertools.takewhile Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-05 22:36 +0100
                Re: Good use for itertools.dropwhile and itertools.takewhile Neil Cerutti <neilc@norwich.edu> - 2012-12-06 13:06 +0000
                Re: Good use for itertools.dropwhile and itertools.takewhile Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-06 15:12 +0100
          Re: Good use for itertools.dropwhile and itertools.takewhile Alexander Blinne <news@blinne.net> - 2012-12-06 14:40 +0100
  Re: Good use for itertools.dropwhile and itertools.takewhile Terry Reedy <tjreedy@udel.edu> - 2012-12-04 17:21 -0500
  Re: Good use for itertools.dropwhile and itertools.takewhile Paul Rubin <no.email@nospam.invalid> - 2012-12-06 13:29 -0800

csiph-web