Runtime of python’s if substring in string
The time complexity is O(N) on average, O(NM) worst case (N being the length of the longer string, M, the shorter string you search for). As of Python 3.10, heuristics are used to lower the worst-case scenario to O(N + M) by switching algorithms. The same algorithm is used for str.index(), str.find(), str.__contains__() (the in … Read more