Why use a generator instead of returning a list?
Reveal the answer and explore the explanation.
05MediumHigh priorityWhy use a generator instead of returning a list?
Answer
MediumHigh priority
Why use a generator instead of returning a list?
Answer
Lazy iterator that yields values on demand rather than storing all of them.
Practical example
Stream batches from a large file with yield.
Reference: Further reading ↗