I'm trying to get the indices of all the elements which match a certain condition in my_list
.
my_list = ['This is chapter 1', 'chapter 2 is here', 'Baseball Sport', 'Football Sport', 'chapter 13']
I want to get all the indices of the elements in my_list
which contain the string 'chapter'
.
I've tried list comprehensions but I'm still new so ain't getting successful.
search = 'Chapter'
for k in range(len(my_list)):
search_list = [i for i, search in enumerate(my_list)
if search.lower() in my_list[k]]
I'm probably doing some mistake here which can't yet identify. How can I get my desired result of indices?
search_list = [0, 1, 4]