nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
8 of 14
1What are the common built-in data types in Python?
2what is an array
3Since Python 3.7, dictionaries preserve insertion order. How is this guaranteed internally, and what changed from earlier versions?
4What is the difference between str.format(), %-formatting, and f-strings? What are the performance and readability tradeoffs?
5When would you use collections.deque instead of a list, and why?
6Why are strings immutable in Python, and what performance implications does this have for repeated concatenation in a loop?
7What problem does collections.defaultdict solve, and how does it differ from using dict.setdefault?
8How would you efficiently remove duplicates from a list while preserving order?
9How would you design a Least Recently Used (LRU) cache using Python's built-in data structures?
10How does a Python dictionary achieve average O(1) lookup time internally?
11What is the difference between a list and a tuple, and when would you choose one over the other?
12What are the time complexities of common list operations (indexing, append, insert, pop, search)?
13What is the difference between a set and a frozenset?
14How does Python handle Unicode internally, and what is the difference between str and bytes?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
08 / 14

How would you efficiently remove duplicates from a list while preserving order?

Difficulty: 5/10
Lists, Dictionaries, Sets, Deduplication

Order-preserving deduplication with dict.fromkeys

The idiomatic Python 3.7+ solution is list(dict.fromkeys(items)). A dict preserves insertion order and keys are unique, so the first occurrence of each hashable item is kept in order. If items are not hashable, you cannot use a dict or set directly; you need a different equality strategy, such as serializing to a hashable key or using an O(n^2) comparison fallback.

  1. 1

    dict.fromkeys is concise and preserves first-occurrence order.

  2. 2

    A seen set plus list append is also O(n) and can be faster if you need custom filtering logic.

  3. 3

    Trade-off: dict.fromkeys builds a dict, while seen-set builds a set. Both are O(n) average time and O(n) space.

  4. 4

    Common mistake: using list(set(items)), which removes duplicates but destroys order.

  5. 5

    Version note: dict.fromkeys order preservation relies on Python 3.7+ dict insertion order guarantee.

javascript

Scenario Questions

0-2 years experience

  1. 1You have [1,2,1,3] and need unique values in original order. What do you do?
  2. 2Why does list(set(items)) not preserve order?

2-5 years experience

  1. 1You need to deduplicate a list of dicts by id while keeping first occurrence. How?
  2. 2You have unhashable elements. How do you preserve order without O(n^2) if possible?

5-8 years experience

  1. 1You stream a large log and need first occurrence per user ID with bounded memory. What data structure?
  2. 2You need stable deduplication across batches. How do you scale?

8+ years experience

  1. 1Design an order-preserving deduplication pipeline for billions of records with exactly-once semantics.
  2. 2You need dedupe with custom equality for near-duplicates. How do you avoid hashing pitfalls?

Follow-up Questions

  • What if the list contains dictionaries? How do you deduplicate by a specific key?
  • How would you deduplicate a stream that does not fit in memory?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.