TryBugHunt
All collections
🐍Language Quirks ~20 mins

Python Gotchas

The classic Python traps that trick everyone

Mutable default arguments, list.sort() returning None, and mutating a list while iterating over it.

PythonMedium5 Challenges

Your Progress

0 of 5 completed

Start Collection

Challenges in this collection

  1. 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"].

    easy
  2. 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]].

    medium
  3. 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"].

    easy
  4. 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].

    medium
  5. 5

    Shopping total crashes at the end of the list

    cart_total(prices) adds up every price. Example: cart_total([10, 20, 30]) → 60.

    easy

More collections to explore