Loading...
The Lazy Stream
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- senior, staff
Problem
Implement a generator class that accepts another iterable and yields its elements one at a time. Then implement a second class that wraps the first and lazily flattens one level of nesting - if a yielded element is itself iterable (but not a string), yield its elements individually. Demonstrate with a test sequence.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.