Skip to content

Instantly share code, notes, and snippets.

@PANDATD
Last active May 11, 2021 20:28
Show Gist options
  • Select an option

  • Save PANDATD/90d36a0e209a7d17cb836590769ebe57 to your computer and use it in GitHub Desktop.

Select an option

Save PANDATD/90d36a0e209a7d17cb836590769ebe57 to your computer and use it in GitHub Desktop.
def lsearch(array:list, search_element:any)->None:
"""
This funcation will help to search
element using linear search algorithm.
>>> lsearch ([134,56,2,78,0],78)
Element is Found at 4th index and 5th position
"""
i = 0
for i in range(len(array)):
if array[i] == search_element:
print("Element is Found at", i,"th index and", i+1, "th position")
break
else:
pass
if i==len(array)-1:
print("Element not found ")
i = i+1
if __name__ == "__main__":
import doctest
doctest.testmod(name="lsearch",verbose=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment