Saurabh Verma
Saurabh Verma

Reputation: 43

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

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.

Upvotes: 0

Views: 77

Answers (2)

Dmitriy Neledva
Dmitriy Neledva

Reputation: 864

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"

Upvotes: 3

user1196549
user1196549

Reputation:

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.

Upvotes: 2

Related Questions