In python I have, for example, the following string:
a = "Sentence with weird whitespaces"
I want the same string with extended whitespaces replaced by just one, so the final string would read
'Sentence with weird whitespaces'
I found a solution myself, but is there a better/shorter one?
' '.join([x for x in a.split(' ') if len(x)>0])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With