Haz
Haz

Reputation: 361

Identify the first sentence from a paragraph using python

I want to get the first sentence from a paragraph using python. the paragraph as below

ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US dollar on Friday and gilt yields edged higher on profit taking in the secondary market even as the Central Bank cut policy rates to revive credit demand, while stocks ended 0.26 percent lower, market participants said.

The rupee ended at 176.40/50 rupees against the greenback in the spot market on Thursday.

which i was written from the below code was extracting the sentence until the decimal place. Thanks for help.

import requests
#from pprint import pprint
from IPython.display import HTML
import json


txt = ''' ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US dollar on Friday and gilt yields edged higher on profit taking in the secondary market even as the Central Bank cut policy rates to revive credit demand, while stocks ended 0.26 percent lower, market participants said.

The rupee ended at 176.40/50 rupees against the greenback in the spot market on Thursday. '''

if len(txt) > 100:
    txt = txt.partition('.')[0] + '.'
print(txt)

Upvotes: 0

Views: 86

Answers (2)

Urvi Soni
Urvi Soni

Reputation: 314

You can try this...

txt = " ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US 
        dollar on Friday and gilt yields edged higher on profit taking in the 
        secondary market even as the Central Bank cut policy rates to revive credit 
        demand, while stocks ended 0.26 percent lower, market participants said. The 
        rupee ended at 176.40/50 rupees against the greenback in the spot market on 
        Thursday. "

sentence_index = txt.find('. ')

print(txt[0: sentence_index])

You will get output like as follow

ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US dollar on Friday and gilt yields edged higher on profit taking in the secondary market even as the Central Bank cut policy rates to revive credit demand, while stocks ended 0.26 percent lower, market participants said

Upvotes: 1

DijkWxyZ
DijkWxyZ

Reputation: 86

try to split with '. '(with a space) and '.\n'

Upvotes: 1

Related Questions