1

In Python, we can use in to search in strings, lists, sets, etc. like
if x in string:
But which search algorithm is internally implemented?

CoolCoder
  • 786
  • 7
  • 20
  • 1
    The duplicate only answers your question for strings, but the implementation is different for each type anyway. You might consider reading the source code for CPython for a specific implementation. – Selcuk Apr 12 '21 at 02:07

1 Answers1

1

The implemented search algorithm is at the vendor's discretion. You need to consult your vendor's documentation for that. Also note that the algorithm will vary by data type: unrestricted sequences will require some form of linear search; sorted ones will have bisection or interpolation; dicts and sets use a constant-time hash key.

Prune
  • 76,765
  • 14
  • 60
  • 81