Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

truncate spaces in python

s = '  Hello  World   From Pankaj 	

	Hi There  '
>>> s.strip()
'Hello  World   From Pankaj 	

	Hi There'
>>> s.replace(" ", "")
'HelloWorldFromPankaj	

	HiThere'
>>> " ".join(s.split())
'Hello World From Pankaj Hi There'
>>> import string
>>> s.translate({ord(c): None for c in string.whitespace})
'HelloWorldFromPankajHiThere'
Source by www.journaldev.com #
 
PREVIOUS NEXT
Tagged: #truncate #spaces #python
ADD COMMENT
Topic
Name
4+8 =