Answers for "python find all the matches in array"

2

python return index of second match

# 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
4

get all indices of a value in list python

indices = [i for i, x in enumerate(my_list) if x == "whatever"]
Posted by: Guest on March-11-2020

Code answers related to "python find all the matches in array"

Python Answers by Framework

Browse Popular Code Answers by Language