Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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.111 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.01; 'subsequent': 0.04; 'pretend': 0.07; 'dec': 0.15; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'subject:skip:i 10': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'problem': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'false': 0.35; 'fresh': 0.35; 'received:209.85': 0.35; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'red': 0.60; "you've": 0.61; 'limit': 0.65; 'groups.': 0.78; 'neil': 0.84; 'to:name:python': 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=STr7J9gmOJOUi1XuvxYPkBNr6qOAcJeLsvlqVfpfekE=; b=pq6Dg2GOK2HMhHjk1882pJSCvUUWhfNTYDhJwV9hUbWSNW57HJv3sqMooZ9NeRy9h6 Q1F8BzbONbwWsR6TKtCEEdxuSGKb+ZqfnfMW972FtMCqyZZGevCV8fvHRvcIkuV2SBtZ 22qXogB7779fwWySSUiEuswexF4lLzzvSmfqTo5bCQd0Bf52ev9tTBSc/gMVLRX5/4IO E7WygbShyUVGAQg/cvAU1NJzXFGAZ64pdnjMD5LdCAMcG6zFULVyWphkaRQ4mO+0A96e m/pC4m55l6yEFItlXHaA6XFNBNgeE6tSlpawdzyC1VCgC902+oUEyz53NgzR6eXNXQpF 9h5g== MIME-Version: 1.0 In-Reply-To: References: <05bca175-2077-4fb8-917e-baee1a43a47d@googlegroups.com> From: Ian Kelly Date: Wed, 5 Dec 2012 08:33:14 -0700 Subject: Re: Good use for itertools.dropwhile and itertools.takewhile To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 11 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354721626 news.xs4all.nl 6950 [2001:888:2000:d::a6]:55911 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34285 On Wed, Dec 5, 2012 at 7:34 AM, Neil Cerutti wrote: > Well, shoot! Then this is a job for groupby, not takewhile. The problem with groupby is that you can't just limit it to two groups. >>> prod_desc("CAPSICUM RED fresh from QLD") ['QLD', 'fresh from'] Once you've got a false key from the groupby, you would need to pretend that any subsequent groups are part of the false group and tack them on.