An event stream never ends, and producers occasionally send the same event twice in quick succession. Write a generator dedupe_recent(events, n) that yields each event (a dict with an "id") unless its id is one of the ids it remembers:
- •it remembers the ids of the last
n events it yielded; when a new id is yielded and n are already remembered, the oldest is forgotten; - •a dropped duplicate doesn't change what is remembered (it doesn't make that id "recent" again);
- •the first copy of an event is the one that passes.
It must be lazy: yield each event as soon as it's decided, read the input no further than needed, and keep memory bounded by n however long the stream runs. n is at least 1.
Python 3.13 in your browser — the standard library plus pandas and numpy; no pip installs.