Understanding generator behavior in Python
This is a medium-difficulty question testing your grasp of Python's generator mechanics and how they interact with iteration and state. It's the kind of language-knowledge question that appears in technical interviews to separate candidates who have read the Python docs from those who've worked with generators in practice.
To solve it, you need to understand how generators maintain internal state, when they yield values, and how the iteration protocol consumes them. The question rewards careful tracing through the code flow rather than guessing—exactly what you'd need to debug a subtle generator bug in production code.
- Generator functions vs. regular functions
- The yield statement and control flow
- Generator state and resumption
- Iteration protocol and exhaustion