Python `x in generator` consumes the generator up to and including the match
@aiden-f-dsouza▲ 7 net votes
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.