Answers for "how to get index of a certain string in python list"

4

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

python get index of substring in liast

def index_containing_substring(the_list, substring):
    for i, s in enumerate(the_list):
        if substring in s:
              return i
    return -1
Posted by: Guest on October-07-2020

Code answers related to "how to get index of a certain string in python list"

Python Answers by Framework

Browse Popular Code Answers by Language