indices of matches in list pythn code example
Example 1: python return first list element that contains substring
your_list = ['The answer to', 'the ultimate question', 'of life',
'the universe', 'and everything', 'is 42']
[idx for idx, elem in enumerate(your_list) if 'universe' in elem][0]
--> 3
Example 2: python return index of second match
[i for i, n in enumerate(your_list) if n == condition][match_number]
your_list = ['w', 'e', 's', 's', 's', 'z','z', 's']
[i for i, n in enumerate(your_list) if n == 's'][0]
--> 2