Answers for "get all indexs of string in string"

0

find all indices of element in string python

def find(s, ch):
    return [i for i, ltr in enumerate(s) if ltr == ch]
Posted by: Guest on October-03-2021
2

how to get all index of a char of a string in python

word = 'Hello'
to_find = 'l'

# in one line
print([i for i, x in enumerate(word) if x == to_find])
Posted by: Guest on June-03-2021

Code answers related to "get all indexs of string in string"

Python Answers by Framework

Browse Popular Code Answers by Language