ValueError: too many values to unpack (expected 2)
The left side of an assignment names fewer variables than the right side produced. Usually a split() with an extra part, or a loop over a dictionary without .items().
What it means
a, b = something unpacks exactly two items. If something yields three, Python stops rather than guess which one to drop. Python 3.13 adds the actual count, for example (expected 2, got 3). The opposite mismatch raises "not enough values to unpack".
Common causes
1. Splitting text that has more parts than you assumed
Real names, addresses and file names have more pieces than the example.
Breaks
first, last = "Mary Ann Smith".split()Works
parts = full_name.split()
first, last = parts[0], parts[-1]2. Looping over a dictionary without .items()
A dict gives you its keys, and each key string is then unpacked letter by letter.
Breaks
for name, score in scores:
print(name, score)Works
for name, score in scores.items():
print(name, score)3. A row with an extra column
Data files grow columns; unpacking code does not notice.
Breaks
for name, age in rows: # rows now have 3 columns
...Works
for name, age, *rest in rows:
...How to find it in your own code
Print the right-hand side, and its len(), just before the line. A dictionary needs .items(); a split needs a decision about the extra parts, or a starred catch-all: first, *middle, last = parts.
Still not sure why yours breaks?
Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.