I'm sure this is simple and I'm looking right at it, but I cannot make it work.
Goal: Use a loop to go through the list of strings and find the search term. Return the element number of the first match.
I've tried a few options, nothing seems to work, and I have yet to find a working description of how to do it in any texts.
This is my best attempt so far:
def get_element_number(a_list, search_term):
for i in range(len(a_list)):
if search_term in a_list[i]:
return a_list.index(i)
elif not search_term in a_list:
return 'no match'
Error message:
Traceback (most recent call last):
File "python", line 11, in <module>
File "python", line 5, in get_element_number
ValueError: 2 is not in list
Not looking for the complete answer, just any help in where I'm going wrong or if I'm missing something would be very helpful.
a_listandsearch_termas made in the function call?