Python | Linear search on list or tuples
Let us see a basic linear search operation on Python lists and tuples. A simple approach is to do a linear search, that is
- Start from the leftmost element of the list and one by one compare x with each element of the list.
- If x matches with an element, return True.
- If x doesn’t match with any of the elements, return False.
Example #1: Linear Search on Lists
Note: that lists are mutable but tuples are not.
Example #2: Linear Search in Tuple