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: 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; '"': 0.09; '")': 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; '>>>': 0.22; 'subject:skip:i 10': 0.22; '>': 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: <50be3049$0$9517$9b4e6d93@newsspool1.arcor-online.net> <50be4566$0$9507$9b4e6d93@newsspool1.arcor-online.net> From: Ian Kelly Date: Tue, 4 Dec 2012 12:37:38 -0700 Subject: Re: Good use for itertools.dropwhile and itertools.takewhile To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --bcaec55404986bf7cb04d00c01ce Content-Type: text/plain; charset=ISO-8859-1 On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinne 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 "", line 1, in > > 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 "", line 1, in File "", 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 "", line 1, in File "", line 14, in prod_desc IndexError: string index out of range --bcaec55404986bf7cb04d00c01ce Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinn= e <news@blinne.net> wrote:
Am 04.12.2012 19:28, schrieb DJC:
>>>> (i for i,v in enumerate(w) if v.upper() = !=3D v).next()
> Traceback (most recent call last):
> =A0 File "<stdin>", line 1, in <module>
> AttributeError: 'generator' object has no attribute 'next&= #39;

Yeah, i saw this problem right after i sent the posting. It now is supposed to read like this

>>> def split_product(p):
... =A0 =A0 w =3D p.split(" ")
... =A0 =A0 j =3D next(i for i,v in enumerate(w) if v.upper() !=3D v)=
... =A0 =A0 return " ".join(w[:j]), " &quo= t;.join(w[j:])

It still fails if the produc= t description is empty.

>>> split_product("CAPSICUM RE= D")
Traceback (most recent call last):
=A0 File "<stdin>", l= ine 1, in <module>
=A0 File "<stdin>", line 3, in = split_product
StopIteration

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

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

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

--bcaec55404986bf7cb04d00c01ce--