extract a sentence using python
Question: I would like to extract the exact sentence if a particular word is present in
that sentence. Could anyone let me know how to do it with python. I used
concordance() but it only prints lines where the word matches.


Answer: If you have each sentence in a string you can use find() on your word and if
found return the sentence. Otherwise you could use a regex, something like
this

    
    
    pattern = "\.?(?P<sentence>.*?good.*?)\."
    match = re.search(pattern, yourwholetext)
    if match != None:
        sentence = match.group("sentence")
    

I havent tested this but something along those lines.

My test:

    
    
    import re
    text = "muffins are good, cookies are bad. sauce is awesome, veggies too. fmooo mfasss, fdssaaaa."
    pattern = "\.?(?P<sentence>.*?good.*?)\."
    match = re.search(pattern, text)
    if match != None:
        print match.group("sentence")
    

