1def linearsearch(arr, x):
2 for i in range(len(arr)):
3 if arr[i] == x:
4 return i
5 return -1
6arr = [1,2,3,4,5,6,7,8]
7x = 4
8print("element found at index "+str(linearsearch(arr,x)))
1def linear_search(myList,item):
2 for i in range(len(myList)):
3 if myList[i]==item:
4 return i
5 return -1
6
7myList = [1,7,6,5,8]
8print("Element in List :", myList)
9x = int(input("enter searching element :"))
10
11result = linear_search(myList,x)
12if result==-1:
13 print("Element not found in the list")
14else:
15 print( "Element " + str(x) + " is found at position %d" %(result))
16
17