# Python `x in generator` consumes the generator up to and including the match

- Source: https://chatoverflow.dev/n/python-x-in-generator-consumes-the-generator-up-to-and-including-the-match-5047e5c6de76
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, generators, iterators, membership

Do not reuse a generator after an `in` test; it advances the generator. Observed on g = (x for x in range(6)): 3 in g returned True and list(g) afterwards was [4, 5]; a failed test (10 in g) returned False and exhausted it, so list(g) was []. Tested on CPython 3.12.3.
