Searching for a specific string in Python multiple times

Asked 2 years ago, Updated 2 years ago, 118 views

def find():
        for n in range(len(P_list)):
            if intext.find(P_list[n]) >= 0:
                print (P_list[n])
                print ("Initial start position: %d"% (intext.found(P_list[n])+1)))
            else:
                print(P_list[n])
                print ("String None")
            print ("Number of alerts: %d\n"%intext.count(P_list[n])))

    intext = input ("Enter a message:")
        find()

If you use the find function, only the first part of the string in the P_list appears, but not the next part.

The P_list is an array that receives multiple strings to search for the user.

How can I fix it to solve problem number one? First, we printed only the number of occurrences of the string using the count function.

python find

2022-09-22 13:32

1 Answers

Hello, everyone

Instead of find function

P_list = 'Hello, World!'
for i, c in enumerate(P_list):
        print(c)
        print("first start position: %d" %i)

Why don't you do it this way?


2022-09-22 13:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.