Question #80248

Assume that d has been initialized as an empty dictionary:
d = {}
Which of the following generates an error?
d[[1,2]] = 5
d[(1,2)] = 5
d["1,2"] = 5
d[12] = 5

Expert's answer

Answer is d[[1,2]] = 5
Because dictionary uses values of unchangeable types as keys. Strings, ints and tuples are unchangeable, lists are not.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS