What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
First split lines then join them by any separator you like:
x = ' '.join(x.splitlines())
should work like a charm.