Use a list for an ordered sequence that may change, a tuple for an ordered sequence whose item references should stay fixed, a set for unique values and set operations, and a dict to associate keys with values. The right choice depends on whether position, changeability, duplicates, or key-based lookup matters.
How the four Python collection types differ
| Type | Ordering and access | Can the collection change? | Typical use | Constraint |
|---|---|---|---|---|
list |
Ordered; access by integer index or slice | Yes | A sequence that grows or changes, such as accumulated results | Lists are unhashable |
tuple |
Ordered; access by integer index or unpacking | No, not at the outer collection level | Fixed groups of values, such as coordinates | Hashable only if every element is hashable |
set |
Unordered; test membership, but do not index by position | Yes; frozenset is the immutable counterpart |
Unique values, membership checks, and set operations | Elements must be hashable |
dict |
Retrieve by key; iteration follows insertion order | Yes | Associate each key with a value | Keys must be hashable and unique |
Python’s official data structures tutorial describes sets as unordered collections with no duplicate elements. The language reference documents the underlying mutability, mapping, and ordering rules. These are different tools, not a ranking: select by the behavior your data needs.
When to use a list
A list is a mutable sequence. Write one with square brackets:
items = ["tea", "coffee"]
Lists preserve positions, so use an index or slice to access part of the sequence. Methods such as append change a list in place:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
items.append("water")
Mutation affects the existing list object. If another variable refers to that same object, changing the list through either name is visible through both. Assigning a list to another name does not, by itself, make a copy.
When to use a tuple
A tuple is an ordered sequence that cannot have its own item references reassigned. It is useful for a fixed group of values, such as a coordinate:
Rank #2
point = (3, 4)
x, y = point
Commas make tuples. A one-item tuple needs a trailing comma: single = (3,). By contrast, (3) is simply the integer 3; parentheses alone can group an expression.
Immutability does not freeze nested objects
A tuple can contain a mutable object. The tuple’s reference to that object cannot be replaced, but the object itself may still change. For example, if a tuple contains a list, that inner list can be modified.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →This distinction also matters for hashability. A tuple is usable as a dictionary key or set element only when all of its contents are hashable. Attempting to hash a tuple containing an unhashable value, such as a list, raises TypeError. Python’s glossary definition of hashable explains the connection to dictionary keys and set members.
When to use a set
A set holds unique, hashable elements and is useful when duplicates should collapse, when checking whether a value is present, or when comparing groups of values. For example, set(["red", "red", "blue"]) contains one "red" and one "blue".
Sets do not have positional indexing. Their display or iteration order should not be treated as sorted or meaningful. For set values a and b, the operators below express common mathematical operations:
a | b: union, values in either seta & b: intersection, values in botha - b: difference, values inabut notba ^ b: symmetric difference, values in either set but not both
Use set() to create an empty set. Empty braces, {}, create an empty dictionary instead.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
When to use a dictionary
A dictionary maps unique, hashable keys to values. Use it when you want to look something up by a meaningful key rather than by its position:
prices = {"tea": 3, "coffee": 4}
tea_price = prices["tea"]
Assigning a value to a key that already exists replaces that key’s previous value. Dictionaries preserve insertion order when iterated: updating an existing key does not move it, while deleting a key and inserting it again places it at the end. Insertion order has been a language guarantee since Python 3.7, as noted in the Python language reference.
Keys must be hashable. Mutable built-in containers such as lists and dictionaries cannot ordinarily be used as keys; a tuple can be a key only when its elements are hashable too.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick Recap
Quick checks for common mistakes
- Need an empty set? Write
set(), not{}. - Need a one-item tuple? Include the comma, as in
(item,). - Need predictable numeric positions? Choose a list or tuple, not a set.
- Need a tuple as a key or set member? Check that every nested value is hashable.
- Need a mutable collection? A list, set, or dictionary can change; a tuple’s own item references cannot.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




