Answers for "get all index a str in list"

3

python3 return a list of indexes of a specific character in a string

string='mississippi'
s='s'
lst= []
for i in range(len(string)):
    if (string[i] == s):
        lst.append(i)
print(lst)
#result: [2, 3, 5, 6]
Posted by: Guest on May-07-2020
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

Python Answers by Framework

Browse Popular Code Answers by Language