I have heard that when you perform an in
operator on a list it has to search through O(n) objects while if you do it on a set it has to search through O(1) objects. To see what I mean go here. Does this still apply to OrderedSet
?
Asked
Active
Viewed 28 times
0

Fateh
- 302
- 2
- 12
1 Answers
1
Which OrderedSet
are you talking about? At this time (Python 3.8.3), there is not OrderedSet
in the standard library.
Typically, OrderedSet implementations will implement __contains__
by delegating to the underlying set
. So it will have the algorithmic complexity you would expect.

ddaa
- 52,890
- 7
- 50
- 59
-
I was talking about ```OrderedSet``` from collections but your answer still works. – Fateh May 14 '20 at 13:53
-
There is no `OrderedSet` in collections. There is a separate module, but that is not part of Standard Library. – Sayandip Dutta May 14 '20 at 14:57
-
Oh snap, I was thinking of ```OrderedDict```. Sorry. – Fateh May 14 '20 at 15:47