Home > Mobile >  What is the data type used by set in python internally?
What is the data type used by set in python internally?

Time:11-21

Interviewer asked me that what is the data type used by set internally in python and what is the time complexity of inserting value in set.

I tried to search on google but I am not getting any specific answer in google search.

Also, I tried to find the set class to check data type used by set in python but not able to find.

CodePudding user response:

Given that "a set is a collection which is unordered, unchangeable, and unindexed" and it can hold data of any type, you can guess that a set is a hash table. It is a simplified dictionary.

CodePudding user response:

set as well as dict use hash table as internal data type. As described in the Python documentation:

"A set object is an unordered collection of distinct hashable objects"

  • Related