Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; '"""': 0.05; 'failing': 0.05; 'underlying': 0.09; 'cc:addr:python-list': 0.10; 'stored': 0.10; 'weird': 0.15; 'advanced,': 0.16; 'iterable': 0.16; 'iterator': 0.16; 'result:': 0.16; 'wrote:': 0.17; 'tests': 0.18; 'feb': 0.19; 'trying': 0.21; 'sorry,': 0.22; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'list:': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'noticed': 0.28; 'url:mailman': 0.29; 'source': 0.29; 'worked': 0.30; 'returned': 0.30; 'code': 0.31; 'url:python': 0.32; 'url:listinfo': 0.32; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'needed': 0.35; 'so,': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'itself': 0.37; 'previous': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'unit': 0.38; 'object': 0.38; 'performance': 0.39; 'where': 0.40; 'url:mail': 0.40; 'situation': 0.62; 'strange': 0.62; 'production': 0.63; 'more': 0.63; '26,': 0.65; 'stated': 0.69; 'carefully': 0.71; 'sharing': 0.74; 'funny': 0.78; '2013': 0.84; 'andrea': 0.84; 'shared,': 0.84; 'shares': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=8HgwkTN6eHqUostqjOMKmkhO+5O8V3Y+Kzr+7vafFyU=; b=KOwzOGxPtKJPRsX8pt3KtsMIertlMMTV4zIE6hKBRFkGDp6tsqZXndfdDiUd++siIr dEjBWGu085mBMjoOQc35qaXP5GHHjjW2X2LgYuU0DlFMjvZ00fQtqepj0LNeAZErnu9K sNnuHqdsoE1dEZkQlMjy6AOt10d9+guAF5uICmGm/XdJburFrQq3bylxa3gJWmDbsgYk Ymb8C1q+xy0aAARHG5i4Z3itsiwazJrtf3fHovN2YHkSYX36AnBju+XqrJx333HmN49y /ByzbEbWcQbLBTtRgutxsRX91CqPsaIipzwl2bQhzEelkU7ijem81RW6lP2FHgAcFFE/ pwlQ== MIME-Version: 1.0 X-Received: by 10.43.62.12 with SMTP id wy12mr6526763icb.19.1361898564106; Tue, 26 Feb 2013 09:09:24 -0800 (PST) In-Reply-To: References: Date: Tue, 26 Feb 2013 17:09:24 +0000 Subject: Re: groupby behaviour From: andrea crotti To: Ian Kelly Content-Type: text/plain; charset=ISO-8859-1 Cc: Python 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361898573 news.xs4all.nl 6860 [2001:888:2000:d::a6]:38853 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39975 2013/2/26 Ian Kelly : > On Tue, Feb 26, 2013 at 9:27 AM, andrea crotti > wrote: >> So I was trying to use groupby (which I used in the past), but I >> noticed a very strange thing if using list on >> the result: > > As stated in the docs: > > """ > The returned group is itself an iterator that shares the underlying > iterable with groupby(). Because the source is shared, when the > groupby() object is advanced, the previous group is no longer visible. > So, if that data is needed later, it should be stored as a list: > """ > -- > http://mail.python.org/mailman/listinfo/python-list I should have read more carefully sorry, I was in the funny situation where it would have actually worked in the production code but it was failing in the unit tests (because I was using list only there). It's very weird though this sharing and still doesn't really look rightl, is it done just for performance reasons?