cartagenae icon

Linear Search (review)

cartagenae | PRO | 11/18/18 11:12:03 AM UTC | 0 ⭐ | 389 👁️ | Never ⏰ | []
text |

380 B

|

None

|

0 👍

/

0 👎

# A list of the ingredients for tuna sushi
recipe = ["nori", "tuna", "soy sauce", "sushi rice"]
target_ingredient = "avocado"
 def linear_search(search_list, target_value):
  for idx in range(len(search_list)):
    if search_list[idx] == target_value:
      return idx
  raise ValueError("{0} not in list".format(target_value))
 print(linear_search(recipe, target_ingredient))

Comments