โ† Python
#7 most askedVery commonMediumIterators & generators

Generators and yield

๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Write a generator chunks(items, size) that yields lists of size items (the last one may be shorter). Then explain why generators save memory.

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def chunks(items, size):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.