The position index of the string output letter in the string

Enter a string, then enter two characters, and find the index of these two characters in the string.

Input format:

Enter the string on the
first line. Enter two characters on the second line, separated by spaces.

Output format:

The character and index are output in reverse, that is, the last one is output first. One per line.

Input sample:

Here is a set of inputs. E.g:

Mississippi
sp
output sample:

The corresponding output is given here. E.g:

9 p
8 p
6 s
5 s
3 s
2 s

str = input()
code=input().split()
#a,b= input().split()
l= len(str)-1
#字符串逆序
str = str [::-1]
#for i in range (l):
for ch in str:
    #if lst[i]==code[2]:
    if ch == code[0] or ch == code[1]:
        print(l, ch)

    l-=1

String

Guess you like

Origin blog.csdn.net/m0_46407213/article/details/109155906