python

Python - String, renove all single character for text

# renove all single character for text

text = "t is a  c         test for removing                         multiple spaces"

document =' '.join( [w for w in text.split() if len(w)>1] )

print(document)
Output
is test for removing multiple spaces

This version removes all single chars, and spaces with one space, we have regex version too.

Was this helpful?