Python | Linear search on list or tuples
Let’s see a basic linear search operation on Python list and tuples.
A simple approach is to do linear search, i.e
- Start from the leftmost element of 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 elements, return False.
Example #1: Linear Search on Lists
Note that list are mutable but tuples are not.
Example #2: Linear Search in Tuple
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course