0 votes
1 view
in Python by (40.4k 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 (92.9k 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 in Python by Sammy (40.4k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...