Answer to Question #93275 in Python for alekhya

Question #93275
Assume that d has been initialized as an empty dictionary:
d = {}
Which of the following generates an error?
d[12] = 5
d["1,2"] = 5
d[(1,2)] = 5
d[[1,2]] = 5
1
Expert's answer
2019-08-26T06:37:39-0400

d[12] = 5        - ok, result of the operation is d = {12: 5}

d["1,2"] = 5    - ok, result of the operation is d = {'1,2': 5}

                         total result is d = {12: 5, '1,2': 5}

d[(1,2)] = 5     - ok, result of the operation is d = {(1,2): 5}

                         total result is d = {12: 5, '1,2': 5, (1,2): 5}

d[[1,2]] = 5     - error, list cannot be in the index of dictionary

 

Answer

 

d[[1,2]] = 5 generates an error


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
APPROVED BY CLIENTS