Skip to content

Instantly share code, notes, and snippets.

@RaMSFT
Created October 21, 2022 12:21
Show Gist options
  • Save RaMSFT/6daf213114eb8c6763e597421f78f290 to your computer and use it in GitHub Desktop.
Save RaMSFT/6daf213114eb8c6763e597421f78f290 to your computer and use it in GitHub Desktop.
def find_index(input_list, search_str):
try:
val = input_list.index(search_str)
return f"index of {search_str} is {val}"
except:
return f"index of {search_str} is not found"
print(find_index(["hi", "edabit", "fgh", "abc"], 'fgh'))
print(find_index(["Red", "blue", "Blue", "Green"], 'blue'))
print(find_index(["a", "g", "y", "d"], 'd'))
print(find_index(["Pineapple", "Orange", "Grape", "Apple"], "Pineapple"))
print(find_index(["Pineapple", "Orange", "Grape", "Apple"], "pp"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment