Answer to Question #80248 in Python for Padhu

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
1
Expert's answer
2018-08-30T03:53:46-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS