-2

data= "Mr. Amitabh Bachchan born 11 October 1942 is an Indian film actor, film producer, television host, occasional playback singer and former politician. He first gained popularity in the early 1970s for films such as Zanjeer, Deewaar and Sholay, and was dubbed India's "angry young man" for his on-screen roles in Hindi films. Referred to as the Shahenshah of Bollywood (in reference to his 1988 film Shahenshah), Sadi ka Mahanayak (Hindi for, "Greatest actor of the century"), Star of the Millennium, or Big B, he has since appeared in over 200 Indian films in a career spanning more than five decades.Bachchan is regarded as one of the greatest actors in the history of Indian cinema."

Output:"Mr.Amitabh Bachchan born 11 October 1942 is an Indian film actor, film producer, television host, occasional playback singer and former politician."

from this unstructured string I want to read only first line. I have tried using readlines() and splitlines() function but no success.I have multiple paragraph with unstructure data , I want to read only first line from the paragraph. Kindly help.

Ayush
  • 95
  • 8

1 Answers1

0

If you already have the text in a variable you can split the text by periods and get the first element:

x = "your text..."
first_line = x.split('.')[0]

That will split the text by periods (.) into an array and get the first element of the array, giving you the first sentence.