Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Ordered Dedup:** dict.fromkeys(lst) (Py 3.7+) or seen=set(); [x for x in lst if not (x in seen or seen.add(x))]. O(n), hashable elements. **Unhashable:** O(n²) with list+in, or convert to tuple for hashable key....
Ordered Dedup: dict.fromkeys(lst) (Py 3.7+) or seen=set(); [x for x in lst if not (x in seen or seen.add(x))]. O(n), hashable elements.
Unhashable: O(n²) with list+in, or convert to tuple for hashable key. For DataFrames: drop_duplicates(subset=['key_col']).
def dedupe(lst):
return list(dict.fromkeys(lst))
Red Flag: Using set(lst) which loses order (pre-3.7). Pro-Move: 'dict.fromkeys for event dedup—first occurrence wins; deterministic replay.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.