Set () runtime in python

Just wondering what search time for set () is? O (1) or O (n)?

if i have

x = set () What is the lead time

if "a" is in x: print a in the set!

+6
python
source share
1 answer

set is implemented using a hash, so searching on average is close to O (1). In the worst case, O (n), where n objects have oncoming hashes.

+9
source share

All Articles