Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed8.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.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'least)': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterated': 0.16; 'iterating': 0.16; 'iterator': 0.16; 'iterators': 0.16; 'sequence.': 0.16; 'trap': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'tried': 0.24; 'header :In-Reply-To:1': 0.24; 'define': 0.27; 'right.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'sentence': 0.29; 'objects': 0.29; 'point': 0.33; 'class': 0.33; 'ones,': 0.33; 'true.': 0.33; 'received:google.com': 0.35; 'instance': 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'no,': 0.38; 'does': 0.39; 'some': 0.40; 'here': 0.66; 'chrisa': 0.84; 'partially': 0.84; 'significance': 0.84; 'to:none': 0.91; '9:00': 0.91; 'subject:membership': 0.91 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=ajc5VuFx222T6phHsmN9aeQSwy3KN7BgSLadqte4BGs=; b=NixkWHfYQlb+/6FXaGhV+Ds8Qe77lsPq/l492/ZDk7AzWEZp+vt5kDSrFicQhFncGr JptTL/HdcLmVi68O+439FYm5jQMzu+QRf2T8VelhZ6XeLsue+vOAQTLhAFGi03cyCTju wAfpXO/w4PnAFwHJ4TG9geuJ1ZnJuZkb9wVXJT7KQbIR15cxLXddu/kKRNv6U15PLFr9 tePfGFACAJ8w7bQVoUwwUWK+iefKygVeOFVlAll/rUCCYrZZ4ew7MrQ4PLSr+l5k+XmZ 5FnO6ZG/arJKiRYvFtakDZQsw1mi51k0ECR0WbcDIZuUzuwnjjxQszcub6DbYTAxMHL2 vhVQ== MIME-Version: 1.0 X-Received: by 10.107.163.11 with SMTP id m11mr16125046ioe.31.1439118625908; Sun, 09 Aug 2015 04:10:25 -0700 (PDT) In-Reply-To: <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> Date: Sun, 9 Aug 2015 21:10:25 +1000 Subject: Re: Iterators membership testing From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439118634 news.xs4all.nl 2967 [2001:888:2000:d::a6]:33421 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95186 On Sun, Aug 9, 2015 at 9:00 PM, Pierre Quentel wrote: >> The trap you're seeing here is that iterating over an iterator always >> consumes it, but mentally, you're expecting this to be iterating over >> a new instance of the same sequence. > > No, I just tried to apply what I read in the docs : > > 1. I have y = A(10) which is an instance of a class which does not define __contains__ but does define __iter__ > > 2. The value z = 0 is produced while iterating over y. > > 3. The sentence "x in y is true if some value z with x == z is produced while iterating over y" lead me to think that "0 in y" would be true. You're almost right. The significance here is that once you've partially iterated over y, the value z will not be produced while iterating over y - so *at that point in time*, y does not contain z. Iterators (non-infinite ones, at least) shrink over time, so the set of objects they contain will shrink. ChrisA