Whats the fastest way of finding the indexes of an item given a list containing it in Python?

I have a list like this but with thousands or maybe millions of elements:

test = [
  ("goodbye", "help", "buy","sell", "", 25), 
  ("hi dude", "text", "friends","love", "blablabla", 14), 
  ("hi darling", "books", "letter","class", "club", 64)

What would be the most optimized code for finding all the elements indexes that contain the word “hi”? In the given example above, it should return test[1] and test[2].


You can use enumerate and any to get the index of all elements that contains the word ‘hi’

>>> test = [("goodbye", "help", "buy","sell", "", 25), ("hi dude", "text", "friends","love", "blablabla", 14), ("hi darling", "books", "letter","class", "club", 64)]
>>> [i for i,words in enumerate(test) if any('hi' in str(word) for word in words)]
[1, 2]