What are the differences between a list, a set, and a dictionary?
💡 Model Answer
A list is an ordered, mutable sequence that allows duplicate elements and supports indexing and slicing. A set is an unordered collection of unique elements; it is mutable but does not support indexing, and membership tests are O(1). A dictionary stores key‑value pairs; keys are unique and hashable, values can be any type. Dictionaries are unordered prior to Python 3.7, but maintain insertion order from 3.7 onward. Use lists for ordered data, sets for membership tests and deduplication, and dictionaries for mapping keys to values. Complexity: list membership O(n), set and dict membership O(1).
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500