#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.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.
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.