xxxxxxxxxx
indices = [i for i, s in enumerate(mylist) if 'aa' in s]
xxxxxxxxxx
# Basic syntax:
index = [idx for idx, elem in enumerate(your_list) if "substring" in elem]
# Example usage:
# Say you wanted to get the index of words containing the substring "hi" in
# the following list:
your_list = ["the", "then", "this", "that", "thine"]
[idx for idx, elem in enumerate(your_list) if "hi" in elem]
--> [2, 4]