In a Meta event ingestion pipeline, you receive a stream of event records in arrival order. Write a function that removes duplicate records while preserving the order of the first occurrence of each unique event.
A record is considered a duplicate if its event_id has already appeared earlier in the stream. Return the filtered list of records in the same relative order as their first appearance.
events, a list of event records"event_id"event_idExample 1
Input: events = [
{"event_id": "a1", "user_id": 10},
{"event_id": "b2", "user_id": 11},
{"event_id": "a1", "user_id": 12}
]
Output: [
{"event_id": "a1", "user_id": 10},
{"event_id": "b2", "user_id": 11}
]
The second a1 is removed because a1 was already seen.
Example 2
Input: events = [
{"event_id": 5},
{"event_id": 5},
{"event_id": 6},
{"event_id": 5}
]
Output: [
{"event_id": 5},
{"event_id": 6}
]
Only the first occurrence of each event_id is kept.
0 <= len(events) <= 10^5event_idevent_id is hashable