Get first list index containing sub-string?
list, python
Solution
A non-slicky method:
def index_containing_substring(the_list, substring):
for i, s in enumerate(the_list):
if substring in s:
return i
return -1
Problem
For lists, the method `list.index(x)` returns the index in the list of the first item whose value is `x`. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this? For example, with ``` l = ['the cat ate the mouse', 'the tiger ate the chicken', 'the horse ate the straw'] ``` this function would return `1` provided with the argument `tiger`.