Python problems.
Solved in 4 minutes each.
Every page here answers one specific question — the exact thing you typed into Google. No filler. Just the answer, working code, the reason it works, and the mistakes to avoid. This is what you need when yield makes no sense, the main guard is a mystery, or your dictionary merge has a subtle bug.
How to use this page. Find your problem in the list below. Click it. The answer is the first thing on the page — no scrolling required. Every page has a "Short answer" box at the top, followed by the working code, then the explanation. If you're looking for a structured learning path instead, the Python learning path covers every concept from scratch.
⚡ Generators
The keyword that confuses every Python beginner.
📦 Collections
Lists, tuples, dicts — the choices that matter.
List vs tuple
Mutable vs immutable, and why tuples can be dict keys. The 27% memory difference.
How to merge two dictionaries
The | operator, {'**d1, **d2'}, and the ChainMap precedence trap.
How to sort a dictionary by value
sorted(d.items(), key=...) — and why you get a list, not a dict.
How to iterate a dictionary
keys(), values(), items() — and the set-operation superpower.
🏗️ Program structure
The idioms that make Python code feel like Python.
🔧 Data manipulation
The operations that come up in every project.
How to check if a file exists
pathlib, os.path, and the try/except pattern that avoids race conditions.
Shallow vs deep copy
The memory diagram, the tuple-of-mutables trap, and when copy.deepcopy is necessary.
Pass by reference or value?
Neither — it's call by sharing. And the mutable default argument trap.
append vs extend vs +=
Three operations that look similar and do very different things.
Python slicing explained
a[start:stop:step] — indices point between elements, and that fixes 90% of off-by-one bugs.
How to flatten a list of lists
itertools.chain.from_iterable and the three methods that actually win.
🧠 Advanced
The concept that makes experienced developers pause.
📋 All 15 problems
Sorted by category. Click any to jump straight to the answer.