If you find yourself doing containment checks inside a loop, your code has an O(n) operation for each step of another O(n) operation, making it O(n*n).
For more on this topic, see my article on the time complexities of different data structures in Python:
pym.dev/time-complex...
The time complexity of common operations on Python's many data structures.