> How efficient is the built in Python set() data type in terms of "is in"?

How efficient is the built in Python set() data type in terms of "is in"?

Posted at: 2014-12-18 
Pretty efficient? That's my guess. Pretty efficient. Or, at least, since the point of python is convenience, it is efficient enough for our purposes

I don't know Python, but a quick Google of 'Python set efficiency" pretty much answers the question.

See first link. Scroll down to the Set section. It claims that x in s has an average time of O(1), and a worst case time of O(n). (That tells me they are probably using a hash of some sort. When there is no hash collision the lookup is O(1). Worst case is every element in the set hashes to the same value which is O(n).

Compare that to a list (top of page), where is x in s has an average time of O(N).

So if x in S is the thing you will be doing the most, then Set is an excellent choice.

See second link for a bit more. Look at the timing test results in the second answer.