Python ma string.find()i string.rfind()pobiera indeks podłańcucha w ciągu.
Zastanawiam się, czy istnieje coś takiego, string.find_all()co może zwrócić wszystkie znalezione indeksy (nie tylko pierwszy od początku, czy pierwszy od końca).
Na przykład:
string = "test test test test"
print string.find('test') # 0
print string.rfind('test') # 15
#this is the goal
print string.find_all('test') # [0,5,10,15]
'ttt'.rfind_all('tt'), co powinno zwrócić „1”
'ttt'.find_all('tt')zwrócić