Computer Science

my_dict = {}
my_dict[(1,2,4)] = 8 
my_dict[[4,2,1]] = 10 
print(my_dict)

Python Dictionaries

7 Likes

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.

Answered By

3 Likes


Related Questions