Answers for "python for each occourcence of string in substring return next word"

3

python find all elements of substring in string

def find_all(a_str, sub):
    start = 0
    while True:
        start = a_str.find(sub, start)
        if start == -1: return
        yield start
        start += len(sub) # use start += 1 to find overlapping matches

list(find_all('spam spam spam spam', 'spam')) # [0, 5, 10, 15]
Posted by: Guest on June-09-2020

Code answers related to "python for each occourcence of string in substring return next word"

Python Answers by Framework

Browse Popular Code Answers by Language