Home > Back-end >  Searching a sentence in paragraph
Searching a sentence in paragraph

Time:03-04

Can anyone suggest a way to search for a sentence in a paragraph with python. A paragraph can have 20 sentences. I want a particular sentense is there in paragraph or not

key="I want a particular"
parag="what is there to know about.Can anyone suggest a way to search for a sentence in a paragraph with python. A paragraph can have 20 sentences. I want a particular sentense is there in paragraph or not"

I want to return true or false, if true need to replace with " found location in paragraph".

CodePudding user response:

key in parag

Will tell you whether your key is in the paragraph or not. You can also use index to find the location of your key within the paragraph.

index = parag.index(key)

if key is not in parag then this will raise a ValueError, but if it is then you will get back the index that key starts at within your paragraph.

  • Related