Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is in the Python something like method findNext() in string?

E.g. I have got text:

"John got up. John went to the cinema. John washed his hand."

Now I would like to find first "John" and do something, then I would like to go to next "John" and do something, so I need to use something like findNext(), which considers the actual position, so it will not be finding from the beginning, but from the actual position.

like image 708
user2104552 Avatar asked Feb 17 '26 23:02

user2104552


1 Answers

The find-Method has a start-argument:

text = "John got up. John went to the cinema. John washed his hand."
pos = -1 
while True:
    pos = text.find('John', pos + 1)
    if pos == -1:
        break
    do_something
like image 197
Daniel Avatar answered Feb 20 '26 12:02

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!