- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Linear Search in Python Program
In this article, we will learn about the Linear Search and its implementation in Python 3.x. Or earlier.
Start from the leftmost element of given arr and one by one compare element x with each element of arr
If x matches with any of the element, return the index value.
If x doesn’t match with any of elements in arr , return -1 or element not found.
Now let’s see the visual representation of the given approach −
def linearsearch(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 arr = ['t','u','t','o','r','i','a','l'] x = 'a' print("element found at index "+str(linearsearch(arr,x)))
Here we linearly scan the list with the help of for loop.
element found at index 6
The scope of the variables are shown in the figure −
In this article, we learnt about the mechanism of linear search in Python3.x. Or earlier
- Python Program for Linear Search
- Write a program for Linear Search in Python
- Java program to implement linear search
- C/C++ Program for Linear Search?
- 8085 Program to perform linear search
- Program to perform linear search in 8085 Microprocessor
- Linear search on list or tuples in Python
- Linear Search
- Linear search in Java.
- Difference Between Linear Search and Binary Search
- C++ Program to Find Minimum Element in an Array using Linear Search
- Linear search using Multi-threading in C
- Python Program for Binary Search
- Python Program for Anagram Substring Search