Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'skip:` 10': 0.07; 'subject:using': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nick': 0.16; 'subject:item': 0.16; 'true:': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'seems': 0.21; 'feb': 0.22; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; 'looks': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'references': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'yield': 0.36; 'next': 0.36; 'pm,': 0.38; 'previous': 0.38; 'subject:[': 0.39; 'release': 0.40; 'around.': 0.60; 'ian': 0.60; "you'll": 0.62; 'forced': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Nj9LZ2zH8k/q+i1KWSQwpJ5NKaGRSxl+Ke+lmvdTvtQ=; b=p6YEqBoEG3pyI9zLCPRVMZYkScad6lykNQY8Y2z5vyD2YG6AtcEkPvwwtvrgLKhK4U 3CTI7/Fjv2MSOK1ijxOsRZSNICt6WI+5R2b6L9Bxq38OmJf/ry3I64V5wU0BZ83yUDjf aNSFGn2e1JbOnIJTtmWF3tO/AqkKfw7UYP/Yzc265r4fdQhiBm81lQ/QvRyQHgGNZIIb qsjtK64dcERlDaBdTYgqqPr0ak1uhKej7eFBfT/tP+eZF978aM38ZTRH/jhfX1aDeFhS mn0EuRLCEXdIC00gYuKYK1GnPF7Vw+6aYq2PJMXNTtkLxY3jTmh+Mi0dKGhtMi1fK73f v8bQ== MIME-Version: 1.0 X-Received: by 10.68.171.229 with SMTP id ax5mr13877792pbc.125.1392450085573; Fri, 14 Feb 2014 23:41:25 -0800 (PST) In-Reply-To: References: Date: Sat, 15 Feb 2014 18:41:25 +1100 Subject: Re: Generator using item[n-1] + item[n] memory From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392450094 news.xs4all.nl 2900 [2001:888:2000:d::a6]:38205 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66391 On Sat, Feb 15, 2014 at 6:27 PM, Ian Kelly wrote: > On Fri, Feb 14, 2014 at 8:31 PM, Nick Timkovich wrote: >> OK, now the trick; adding `data = None` inside the generator works, but in >> my actual code I wrap my generator inside of `enumerate()`, which seems to >> obviate the "fix". Can I get it to play nice or am I forced to count >> manually. Is that a feature? > > Yeah, looks like enumerate also doesn't release its reference to the > previous object until after it gets the next one. You'll just have to > make do without. You could write your own enumerate function. def enumerate(it, i=0): it = iter(it) while True: yield i, next(it) i += 1 That shouldn't keep any extra references around. ChrisA