Iterable as a Key of a Dictionary

Iterable as a Key of a Dictionary

Python dictionaries only accept hashable data types as a key in a dictionary. Using a list as a key will give a TypeError because it is not hashable.

If you want to use an iterable as a key of the dictionary, use a tuple instead. This works because tuples are immutable.

My previous tips on Python dictionary.

Search

Related Posts

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran