Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?

1 Answer

0 votes
by (106k points)

Yes, Python dictionary is an example of a hash mapping or hash table. You can read a description of python's dict implementation:-

That's why you can't use something 'not hashable' as a dict key, like a list:

>>> a = {} 

>>> b = ['some', 'list'] 

>>> hash(b) 

Traceback (most recent call last): 

 File "<stdin>", line 1, in <module> 

TypeError: list objects are unhashable 

>>> a[b] = 'some' 

Traceback (most recent call last): 

 File "<stdin>", line 1, in <module> 

TypeError: list objects are unhashable

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...