Q. The following code has two dictionaries with tuples as keys. While one of these dictionaries being successfully created, the other is giving some error. Find out which dictionary will be successfully and which one will give error and correct it:
dict1 = {(1, 2) : [1, 2], (3, 4) : [3, 4]}
dict2 = {([1], [2]) : [1, 2] : ([3], [4]) : [3, 4]}
Answer =
Dictionary ‘dict1’ will successfully run and dictionary ‘dict2’ will give error.
It can be corrected by removing list from tuple which is as a key.
So,
dict2 = {(1, 2) : [1, 2], (3, 4) : [3, 4]}
corrected code for dict2
ReplyDeletedict2 = {(1, 2) : [1, 2], (3, 4) : [3, 4]}
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )