Answers for "python get index of substring in array of strings"

2

python return first list element that contains substring

# Example usage:
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 # The 0-based index of the first list element containing "universe"
Posted by: Guest on September-28-2020
2

python get index of substring in liast

index = [idx for idx, s in enumerate(l) if 'tiger' in s][0]
Posted by: Guest on October-07-2020

Code answers related to "python get index of substring in array of strings"

Python Answers by Framework

Browse Popular Code Answers by Language