Skip to content

Instantly share code, notes, and snippets.

@msdousti
Created December 24, 2024 22:10
Show Gist options
  • Save msdousti/fe257cb6796750ed72a8fda32ca767c7 to your computer and use it in GitHub Desktop.
Save msdousti/fe257cb6796750ed72a8fda32ca767c7 to your computer and use it in GitHub Desktop.
import sys
def join_paragraph_lines(input_text):
paragraphs = input_text.strip().split('\n\n')
joined_paragraphs = []
for paragraph in paragraphs:
lines = paragraph.splitlines()
sep = ''
aggregate = ''
for i, line in enumerate(lines):
if i == 0:
sep = ''
elif line.startswith('----') or line.startswith('====') or line.startswith('\t'):
sep = '\n'
else:
sep = ' '
aggregate += sep + line
joined_paragraphs.append(aggregate)
return '\n\n'.join(joined_paragraphs)
input_text = sys.stdin.read()
result = join_paragraph_lines(input_text)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment