For instance : I read text from a file and return it as the iterator : lines.
If I want to suppress empty lines I can use filter() : lines.filter(...) etc.
But what if I want to return paragraphs as vectors of consecutive non-empty lines, as in the following python example:
lines = open("some_text.txt")
paragraph = []
paragraph_list = []
def get_paragraphs(paragraph, paragraph_list):
for line in lines:
if len(line.strip()) > 0:
paragraph.append(line)
else:
if len(paragraph) > 0 :
paragraph_list.append(paragraph)
paragraph = []
get_paragraphs(paragraph, paragraph_list)
for item in paragraph_list:
print(item)
print("- - -")