Sobes.tech
Junior — Senior

Errors when choosing keys for defaultdict

livecode

Task condition

It is necessary to find out which of the given lines execute without errors and which cause exceptions, as well as explain the reasons for such behavior.

from collections import defaultdict

my_dict = defaultdict(int)

assert my_dict["key"] == 0
assert my_dict[(1, 2)] == 0
assert my_dict[(1, 2, (3,))] == 0
assert my_dict[(1, 2, [3])] == 0
assert my_dict[(1, 2, {3})] == 0