Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95186
| References | <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <mailman.2.1439112286.3627.python-list@python.org> <b1c0218c-05dd-402b-b2f0-5e0836146f76@googlegroups.com> <mailman.3.1439115197.3627.python-list@python.org> <09cb3411-be3b-4875-9042-af96c7f63504@googlegroups.com> |
|---|---|
| Date | 2015-08-09 21:10 +1000 |
| Subject | Re: Iterators membership testing |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4.1439118634.3627.python-list@python.org> (permalink) |
On Sun, Aug 9, 2015 at 9:00 PM, Pierre Quentel <pierre.quentel@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Iterators membership testing Pierre Quentel <pierre.quentel@gmail.com> - 2015-08-09 02:06 -0700
Re: Iterators membership testing Chris Angelico <rosuav@gmail.com> - 2015-08-09 19:24 +1000
Re: Iterators membership testing Pierre Quentel <pierre.quentel@gmail.com> - 2015-08-09 02:55 -0700
Re: Iterators membership testing Chris Angelico <rosuav@gmail.com> - 2015-08-09 20:13 +1000
Re: Iterators membership testing Pierre Quentel <pierre.quentel@gmail.com> - 2015-08-09 04:00 -0700
Re: Iterators membership testing Chris Angelico <rosuav@gmail.com> - 2015-08-09 21:10 +1000
Re: Iterators membership testing Laura Creighton <lac@openend.se> - 2015-08-09 13:30 +0200
Re: Iterators membership testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-09 14:49 +0100
Re: Iterators membership testing Chris Angelico <rosuav@gmail.com> - 2015-08-09 23:11 +1000
Re: Iterators membership testing Tim Chase <python.list@tim.thechases.com> - 2015-08-09 08:09 -0500
Re: Iterators membership testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-09 14:45 +0100
Re: Iterators membership testing Tim Chase <tim@thechases.com> - 2015-08-09 08:09 -0500
csiph-web