Have you worked with generators and decorators? Which functions have you used?
💡 Model Answer
I have used generators to create memory‑efficient iterators for large data streams. For instance, I wrote a generator that reads a CSV file line by line using the csv module, yielding each row as a dictionary, which allowed me to process millions of records without loading the entire file into memory. I also employed decorators to add functionality to these generators. A common pattern is a @timed decorator that measures the execution time of a generator function, printing the duration when the generator is exhausted. Another example is a @memoize decorator that caches the results of a pure function, which can be applied to a generator that yields expensive computations. These tools together help write clean, modular, and efficient code in Python.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500