Write a function that accepts two strings and returns the indices of all the occurrences of the second string in the first string as a list. If the second string is not present in the first string then it should return -1.

by

Last updated on Nov 5, 2022
Python Practicals (Question 7)

Input

def indices(first, second):
    for i in second:
        if i in first:
            print(test1.index(i))
        if i not in first:
            print(-1)


test1 = input("Enter the first string:\n")
test2 = input("Enter the second string:\n")
indices(test1, test2)

Output

Enter the first string:
hello
Enter the second string:
he
0
1

How useful was this post?

5 star mean very useful & 1 star means not useful at all.

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Tags: