CBSE Class 11 Computer Science Question 93 of 112

Dictionaries — Question 15

Back to all questions
15
Question

Question 11(b)

my_dict = {}
my_dict[(1,2,4)] = 8 
my_dict[[4,2,1]] = 10 
print(my_dict)
Answer
Output
TypeError: unhashable type: 'list'
Explanation

The line my_dict[[4,2,1]] = 10 is in error because a list is being used as a key of the dictionary. Lists being mutable data types are not allowed as keys in a dictionary.