Cloud Stack Ninja

Data is located in a text file, and I want to group the data inside it into sentences. Definition of a sentence is all the rows one after another with at least 1 character in each row. There are blank rows in between the rows with data and so I want the blank rows to mark the beginning and end of a sentence. Is there a way to do this with list comprehension?

Example from text file. Data would look like this:

This is the
first sentence.

This is a really long sentence
and it just keeps going across many
rows there will not necessarily be 
or consistency in word length
the only difference in ending sentence
is the next row will be blank

here would be the third sentence
you see
the blanks between rows of data 
help define what a sentence is

this would be sentence 4
i want to pull data
from text file
as such (in sentences) 
where sentences are defined with
blank records in between

this would be sentence 5 since blank row above it
and continues but ends because blank row(s) below it

Read more here:

Content Attribution

This content was originally published by New_to_Python at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: