Created
December 24, 2024 22:10
-
-
Save msdousti/fe257cb6796750ed72a8fda32ca767c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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