Python Gotchas
The classic Python traps that trick everyone
Mutable default arguments, list.sort() returning None, and mutating a list while iterating over it.
Your Progress
0 of 5 completed
Challenges in this collection
- 1
Sorted name list comes back as None
sorted_names(names) returns the names in A to Z order. Example: sorted_names(["b", "a"]) → ["a", "b"].
pythoneasy - 2
Second list still has the first call's item
append_to_list(val) puts val in a new list when no list is given. test_append() calls it with 1, then with 2. Example: test_append() → [[1], [2]].
pythonmedium - 3
Adding a tag makes the whole list disappear
add_tag(tags, new_tag) adds a tag to the list and returns the list. Example: add_tag(["python"], "debugging") → ["python", "debugging"].
pythoneasy - 4
Merging settings changes the defaults
merge_settings(defaults, overrides) returns a new dict with the overrides on top, and leaves defaults unchanged so it can be reused. check_merge only reports [merged mode, merged size, defaults mode, defaults size]. Fix merge_settings. Example: check_merge({"mode": "light"}, {"size": "big"}) → ["light", 2, "light", 1].
pythonmedium - 5
Shopping total crashes at the end of the list
cart_total(prices) adds up every price. Example: cart_total([10, 20, 30]) → 60.
pythoneasy
More collections to explore
Your First 5 Bugs
Five beginner-friendly bugs with clear symptoms and satisfying fixes. The best place to start if you are new to debugging.
JavaScript Type Coercion Traps
Accidental string concatenation, array sort ordering numbers alphabetically, and zero being falsely treated as missing.
The Off-By-One Gauntlet
Fencepost errors, inclusive vs exclusive slice bounds, and loops that step one position too far.
Async Nightmares
The asynchronous bugs that silently swallow data: un-awaited promises, forEach loops with async callbacks, and race conditions.
AI Code Comprehension
Simulate modern Code Comprehension rounds: classic coding questions written by an AI that pass the obvious test, but break on subtle edge cases.