2017-06-14

Python - How to split a string into paragraphs

data = 'paragraph number one\n number two'
p = 0
for l in data.split('\n'):
p+=1
if l != '':
print p, '\t', l

PS. Assuming paragraphs are delineated by a carriage return (\n).

No comments:

Post a Comment