Created
March 10, 2018 07:17
-
-
Save meetzaveri/221d7f541d429a566692e68726ff541d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Searching an element in a list/array in python | |
# can be simply done using 'in' operator | |
# Example: | |
# if x in arr: | |
# print arr.index(x) | |
# If you want to implement Linear Search in python | |
# Linearly search x in arr[] | |
# If x is present then return its location | |
# else return -1 | |
def search(arr, x): | |
for i in range(len(arr)): | |
if arr[i] == x: | |
return i | |
return -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment