import re s = "This is my first poem\nthat does not make sense\nhow far should it go\nnobody can know.\n\nHere is a seconds\nthat is not as long\ngoodbye\n\n" res = re.sub(r"(?<!\n)\n(?!\n)", " ", s) print(res)
Standard input is empty
This is my first poem that does not make sense how far should it go nobody can know. Here is a seconds that is not as long goodbye