title: Selecting sentences surrounding a keyword
body: <p>I am a Python beginner. I tried to figure this out, but I failed. I need to find a keyword in a text file. If there is the keyword in any part of the whole text, then I need to select sentences surrounding the keyword, including the keyword. The number of sentences is arbitrary so it could be 5 or 10. There could be a blank line between sentences so I need to include the blank line as well.</p>
  
  <p>For example:</p>
  
  <p>Let keyword be: compensation</p>
  
  <p>Let input text is:</p>
  
  <p>"The costs incidental to our solicitation and obtaining of proxies, including the cost of reimbursing banks and brokers for forwarding proxy materials to their principals, will be borne by us. Proxies may be solicited, without extra compensation, by our officers and employees, both in person and by mail, telephone and other methods of communication."</p>
  
  <p>The output I want for example: "The costs incidental... compensation... communication."</p>
  
  <p>I tried to use this: p = re.compile( r'[^.]compensation[^.]+.') p.findall(text)</p>
  
  <p>Using the above code, I can select only the sentence that contains the keyword. What I need is to select sentences surrounding the keyword. I need to control the number of sentences before and after the sentence containing the keyword. SO for example, if I want to select two sentences before the sentence containing the keyword, the sentence containing the keyword, and two sentences after the sentence containing the keyword, what should I do? </p>