Iterators membership testing

Pierre Quentel pierre.quentel at gmail.com
Sun Aug 9 13:00:42 CEST 2015


> 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.


More information about the Python-list mailing list