Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- the_str = 'paragraph1nnparagraph2'
- # splitting should yield ['paragraph1', 'paragraph2']
- the_str = 'p1ntnp2tntstill p2t n ntp3'
- # should yield ['p1', 'p2tntstill p2', 'p3']
- the_str = 'p1nnntp2'
- # should yield ['p1', 'ntp2']
- from itertools import groupby
- def paragraph(lines) :
- for group_separator, line_iteration in groupby(lines.splitlines(True), key = str.isspace) :
- if not group_separator :
- yield ''.join(line_iteration)
- for p in paragraph('p1ntnp2tntstill p2t n ntp'):
- print repr(p)
- 'p1n'
- 'p2tntstill p2t n'
- 'tp3'
- s*?ns*?ns*?
Add Comment
Please, Sign In to add comment