The Listeners
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L4
Problem
Implement an `EventEmitter` with `on(event, listener)` to subscribe, `emit(event, payload)` that returns the payload once per listener currently on that event, and `off(event, listener)` that drops the first matching listener. Then implement `event_broadcaster(op_names, op_args)`, which replays the parallel op sequence against one emitter and collects each result: `None` for the constructor, `on`, and `off`, and the payload list for `emit`.
Summary
Subscribers show up, listen, and sometimes leave.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.