Skip to content

Instantly share code, notes, and snippets.

@Momellouky
Created August 25, 2024 16:55
Show Gist options
  • Save Momellouky/7e52738403cfdf6758701acdafb1840b to your computer and use it in GitHub Desktop.
Save Momellouky/7e52738403cfdf6758701acdafb1840b to your computer and use it in GitHub Desktop.
Linear Search on an array
def linear_search(data, param) -> bool :
for el in data :
if el == param : # We found it
return True
return False
if __name__ == '__main__' :
data = [ 7, 10, 3, 1, 66, 6 ]
param = 1 # The integer we are looking for in the array
try :
number = linear_search(data)
print(f"Number {number} found in the data array")
except :
print(f"Number {param} not found in the array")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment