Answer to Question #297452 in Python for Ram

Question #297452

String Lookup

Ram challenges Anil to a game, He decides to give a target word W to Anil.The rules of the game are very simple.Ram gives Anil N sentences one by one and asks Anil to print the first sentence which contains the given word W.If the sentence numbering starts from 1, can you identify the first sentence number containing the word W?


Note: Consider lower and upper case letters as different.


Input

The first line of input is the word W.

The second line of input is a positive integer N.

The next N lines of input contain a string in each line.


Output

The output should be a single line containing an integer.

If the given word is not in any line of input strings, print -1.


1
Expert's answer
2022-02-13T17:11:54-0500
print('Enter word W: ', end='')
W = input()
print('Enter positive integer N: ', end='')
N = int(input())
numStr = -1
print('Enter strings: ')
for i in range(N):
    S = input()
    for j in S:
        if not j.isalpha():
            S = S.replace(j, ' ')
    Srez = S.split()
    if numStr == -1:
        for j in Srez:
            if (j == W):
                numStr = i + 1
if numStr == -1:
    print('-1')
else:
    print(numStr)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS