Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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]
Comment

PREVIOUS NEXT
Code Example
Python :: int to list python 
Python :: python for else 
Python :: lag function in pandas 
Python :: python creating a dict from a string 
Python :: venv python 
Python :: conda import django 
Python :: accessing index of dataframe python 
Python :: flip key and value in dictionary python 
Python :: power level in google colab 
Python :: how to find the number of times a number appears in python 
Python :: how to play audio in python 
Python :: pillow rgb to grayscale 
Python :: python debugger 
Python :: new env in conda 
Python :: python input function 
Python :: pandas filter dataframe 
Python :: numpy add one column 
Python :: separate path python 
Python :: how to change font in tkinter 
Python :: flask abort return json 
Python :: get sum in range 
Python :: pandas df make set index column 
Python :: manipulate ip address in python 
Python :: minecraft python code 
Python :: python get file path from in os.walk 
Python :: tkinter text blurry 
Python :: df groupby loop 
Python :: how to check if text is in upper case in python 
Python :: how to delete a file in python 
Python :: stop program python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =