Short answer
Use a list when position matters, and a dictionary when you look up a name. A Python list is a mutable sequence indexed by position, and a dictionary maps each hashable key to one value. Since Python 3.7, dictionaries keep insertion order. A repeated key keeps the last value.
Last verified against the sources listed below.
Key takeaways
- The library reference calls a list a mutable sequence, written with square brackets.
- A dictionary maps hashable keys to values. A list cannot be a key.
- Equal keys such as 1, 1.0, and True point at the same dictionary entry.
- Python 3.7 guarantees insertion order. In CPython 3.6 that order was only a detail.
- A missing index raises IndexError. A missing key raises KeyError.
List vs dictionary python is a choice between a sequence you index by position and a mapping you index by key.
Python has both in the language core. The library reference calls lists mutable sequences. It calls a dictionary a mapping from hashable keys to arbitrary objects.
Wikipedia’s page on associative arrays uses dictionary as one name for that second idea: each key appears at most once.
How do you write each one?
A list uses square brackets. A dictionary uses braces and colons, or the dict constructor.
The reference lists four ways to build a list: [], [a, b, c], a comprehension, or list(iterable). list('abc') returns ['a', 'b', 'c']. The items stay in the iterable’s order.
If the argument is already a list, the constructor returns a copy.
A dictionary can be {'jack': 4098, 'sjoerd': 4127}, a comprehension, or dict(foo=100, bar=200). Keyword arguments work only when the keys are valid identifiers. If the same key appears twice while the dict is built, the last value is kept.
What does lookup return?
A list lookup uses an integer position. A dictionary lookup uses a key, and a missing key raises KeyError.
The sequence rules say an index outside the range raises IndexError. Negative indexes count from the end. A slice is a new sequence of the items from the start index up to, but not including, the stop index.
For a dictionary, d[key] returns the value stored under that key. If the key is absent and the class does not define __missing__, the reference says KeyError is raised. len works on both: it is the number of items.
names = ["ada", "grace", "ada"]
scores = {"ada": 10, "grace": 12}
scores["ada"] = 11
names[0] is the first string. scores["ada"] is 11 after the assignment, and the key does not move. That matches the reference: updating a key does not affect order.
Can values repeat?
List items can repeat. Dictionary keys cannot, once two keys compare equal.
Nothing in the list definition demands unique items, so "ada" can sit in two positions. A dictionary is a mapping. Wikipedia states the abstract rule: each possible key appears at most once.
Python’s constructor applies it. The last value for a repeated key wins.
Keys that compare equal share one entry. The reference’s example is 1, 1.0, and True. You cannot store three different values under those three keys.
They are one key.
A list is not a legal key, because it is mutable and unhashable. A tuple of hashable values can be a key. The reference says attempting to hash an immutable sequence that contains an unhashable value raises TypeError.
Which one should you pick?
Pick a list for order and position. Pick a dictionary when the program asks for a value by name.
| Question | List | Dictionary |
|---|---|---|
| Syntax | [a, b, c] or list(...) |
{key: value} or dict(...) |
| Lookup | By position. Out of range raises IndexError | By key. Missing key raises KeyError |
| Duplicates | Items may repeat | A repeated key keeps the last value |
| Order | The sequence order you built | Insertion order, guaranteed in Python 3.7+ |
| Typical use | Steps, rows, a stack of items | A record looked up by id or name |
The 3.7 note is specific. Before that, CPython 3.6 happened to keep insertion order, and other implementations did not have to. Code that must run on 3.6 should not treat order as a promise.
Deleting a key and adding it again puts the new pair at the end. popitem is last-in, first-out as of 3.7 as well.
A word counter can measure a comment you write beside either structure. It does not choose the structure. If the next line of code is items[2], you wanted a list.
If it is items["id"], you wanted a dictionary.
Where do people mix them up?
The common miss is using a list of pairs as a fake mapping, or using a dict when the position is the only key you have.
heapq stores a min-heap in an ordinary list, with the smallest item at index 0. That is still a list. The heap order is an extra rule on top of the sequence, documented on the heapq page, not a reason to switch the data to a dictionary.
A dictionary will not give you “the current minimum” as d[0] unless 0 happens to be one of your keys.
Match statements, added in Python 3.10, can unpack either shape, but they do not change these rules. A pattern can bind list items by position or mapping items by key. The container you built is what decides which pattern fits.
Keep one question in the name of the variable. steps is a list. user_by_id is a dictionary.
If you hear yourself say “the third one,” you are holding a list. If you hear “the one called ada,” you are holding a dictionary. ## How do other languages split the same idea?
JavaScript’s Map holds key-value pairs and remembers insertion order. A C++ priority queue does not.
MDN says a Map key occurs once, any value may be a key, and iteration follows the order of the first set() for that key. That is the dictionary idea, with a different rule for what may be a key. Python still refuses a list as a key.
A Map accepts an object as a key, compared by identity.
Cppreference describes std::priority_queue as an adaptor over a random-access sequence, vector by default. Lookup of the largest element is constant time, and insertion and extraction are logarithmic. std::greater makes the smallest element the top.
That is a heap on a sequence, not a dictionary. If your Python code needs the smallest item, use heapq on a list. If it needs the item named ada, use a dict.
Frequently asked questions
Can a Python list hold duplicate values?
Yes. The library reference defines a list as a mutable sequence of items and does not require those items to be unique. Square brackets with repeated values are still one list. A dictionary is different. Wikipedia's definition of an associative array says each key appears at most once, and Python's constructor agrees: if a key occurs more than once, the last value for that key is the one that remains. Values may repeat. Keys may not, once equality is taken into account.
Does a dictionary remember the order you inserted keys?
Yes, from Python 3.7 onward. The library reference says dictionaries preserve insertion order, and the change note says that order is guaranteed as of 3.7. In CPython 3.6 it was an implementation detail, not a language promise. Updating a value does not move the key. If you delete a key and add it again, the new pair is inserted at the end. Dictionaries became reversible in 3.8, which is a separate note on the same page.
What can be a dictionary key?
The key has to be hashable. The reference says values that contain lists, dictionaries, or other mutable types compared by value may not be keys. A tuple of hashable items can be a key, because an immutable sequence can be hashed. A list cannot. Numbers that compare equal, including 1, 1.0, and True, index the same entry, so they are not three keys. If you need a sequence you can change in place, keep it as a value, or as a list of its own.
When should the collection be a list?
Choose a list when the position is the identity you care about: steps in order, rows as you read them, or a stack you append to and later pop from the end. The reference says lists are typically used for homogeneous items, though it leaves the degree of similarity to the application. Indexing reads sequence[i]. An index outside the range raises IndexError. A dictionary is the wrong container when there is no stable key and you only need 'the third one.'
What does a small example look like?
A list of names can repeat a name. A dictionary of scores cannot have two entries for the same name. If you assign scores['ada'] = 10 and later scores['ada'] = 11, the key ada stays where it was and the value becomes 11. If you delete ada and insert it again, the reference's rule puts that key at the end. list('abc') builds ['a', 'b', 'c'] from the characters, in that order. dict(one=1, two=2) needs keys that are valid identifiers. Other keys use braces.
Sources
- Built-in Types: lists and mappings · Python Software Foundation, 2026
- Associative array · Wikipedia, 2026
- heapq · Python Software Foundation, 2026
- The match statement · Python Software Foundation, 2026
- Map · MDN, 2026
- std::priority_queue · cppreference, 2026