Ctrl K
Python · Senior · Theory

How is a generator different from a regular iterator, and what actually happens on yield? Tell me about send and yield from — where have you used them?

~4 min by voice

How to approach it

They're checking whether you understand the mechanics of generators beyond "a function with yield": the iterator protocol, frame suspension, two-way communication via send/throw, delegation via yield from, and finalization. Plus whether you have real hands-on experience, not just a retelling of the docs.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsThere's a log file of tens of gigabytes; each line contains, separated by spaces, the timestamp, method, path, status, and response time in milliseconds. Write a function top_error_paths that takes the file path and a number k and returns the k paths with the most 5xx responses, along with how many malformed lines were skipped. SeniorWhat's the difference between an iterable and an iterator? How does a for loop work under the hood? JuniorWhat are generators in Python, and how are they different from regular functions? In which cases would you use them? JuniorYou need to process a 20 GB log file: filter the lines and compute some aggregates over them. How would you write that in Python? Mid-level

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min