All articles
Python

Lists vs Tuples vs Sets vs Dictionaries: Which One Do You Need?

Aravind 22 July 2026 7 min read

Python has four built-in ways to hold a group of values. Beginners usually learn lists and then use lists for everything. That works — until it quietly makes your code slow, buggy, or much longer than it needed to be.

Here is how to choose.

The one-line rule

TypeUse it when
ListOrder matters and things will change
TupleOrder matters and nothing should change
SetYou only care whether something is present
DictionaryYou look things up by a name or key

Lists — the default

marks = [85, 92, 78]
marks.append(90)      # [85, 92, 78, 90]
marks[0] = 88         # change an item
print(len(marks))     # 4

Ordered, changeable, allows duplicates. If you are unsure, a list is a reasonable starting point.

Use for: a to-do list, scores in the order they arrived, lines read from a file.

Tuples — a list that is sealed

days = ("Mon", "Tue", "Wed")
print(days[0])        # Mon
days[0] = "Sun"       # TypeError — tuples cannot change

Why would you want something you cannot change? Because "cannot change" is a guarantee. If a coordinate pair, an RGB colour, or a database row should never be edited halfway through your program, a tuple makes that impossible rather than merely unlikely.

Use for: fixed groupings — (latitude, longitude), (width, height), days of the week.

Sets — no duplicates, no order

guests = {"Vijay", "Ajith", "Kamal"}
guests.add("Vijay")   # ignored, already present
print(len(guests))    # 3

A set silently refuses duplicates. It also answers "is this in here?" extremely fast, even with a million items — much faster than a list, which has to check every element one by one.

if "Kamal" in guests:
    print("Already invited")

Use for: removing duplicates, membership checks, tags.

A neat trick — deduplicate a list in one line:

names = ["a", "b", "a", "c", "b"]
unique = list(set(names))    # ['a', 'b', 'c'] (order not guaranteed)

Dictionaries — look up by name

contacts = {
    "Amma": "9876543210",
    "Appa": "9123456780",
}
print(contacts["Amma"])       # 9876543210
contacts["Thambi"] = "90000"  # add a new one

This is the one that changes how you write code. Instead of remembering that position 3 in a list is the phone number, you ask for contacts["Amma"].

Safer lookups, when the key might not exist:

print(contacts.get("Chithi", "Not saved"))   # Not saved

contacts["Chithi"] would crash with a KeyError. .get() lets you supply a fallback.

Use for: anything with a label — settings, counts, records, JSON from an API.

A worked example

Say you want to count how often each word appears in a sentence. With a list it is awkward. With a dictionary it is natural:

sentence = "the cat sat on the mat the end"
counts = {}

for word in sentence.split():
    counts[word] = counts.get(word, 0) + 1

print(counts)
# {'the': 3, 'cat': 1, 'sat': 1, 'on': 1, 'mat': 1, 'end': 1}

That counts.get(word, 0) + 1 pattern — "whatever it was before, or zero, plus one" — is worth memorising. You will use it constantly.

How to actually remember this

Do not memorise the table. Ask two questions about your data:

  1. Do I look things up by a name? → dictionary
  2. If not: does order matter, and will it change? → list if yes, tuple if it must not change, set if you only care about presence

The Python course covers all four with interactive diagrams you can step through one line at a time.

Try the Collections chapter →

Advertisement

Keep reading

10 Reasons Why Python Is the Best First Language
6 min read
Python input() Explained: Why Your Program Stops and Waits
5 min read