Advertisement
cartagenae

Linear Search (review)

Nov 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. # A list of the ingredients for tuna sushi
  2. recipe = ["nori", "tuna", "soy sauce", "sushi rice"]
  3. target_ingredient = "avocado"
  4.  
  5. def linear_search(search_list, target_value):
  6. for idx in range(len(search_list)):
  7. if search_list[idx] == target_value:
  8. return idx
  9. raise ValueError("{0} not in list".format(target_value))
  10.  
  11. print(linear_search(recipe, target_ingredient))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement