1
2def find_all_indexes(input_str, search_str):
3 l1 = []
4 length = len(input_str)
5 index = 0
6 while index < length:
7 i = input_str.find(search_str, index)
8 if i == -1:
9 return l1
10 l1.append(i)
11 index = i + 1
12 return l1
13
14
15s = 'abaacdaa12aa2'
16print(find_all_indexes(s, 'a'))
17print(find_all_indexes(s, 'aa'))
18
1def find_all_indexes2(input_str, search_str):
2 indexes = []
3 index = input_str.find(search_str)
4
5 while index != -1:
6 indexes.append(index)
7 index = input_str.find(search_str, index+1)
8
9 return indexes
10
11print(find_all_indexes2("Can you can a can as a canner can can a can", "can"))
12# returns [8, 14, 23, 30, 34, 40]
13# Note: Capital "Can" was not found