Search
 
SCRIPT & CODE EXAMPLE
 

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'
Comment

PREVIOUS NEXT
Code Example
Python :: permutation and combination in python 
Python :: filter function in python 
Python :: what is an object in python 
Python :: how to encode a string in python 
Python :: Python RegEx Compile – re.compile() 
Python :: how can I print all items in a tuple, separated by commas? 
Python :: convert file dta in csv 
Python :: number string array 
Python :: set lable of field django 
Python :: python mongodb docker 
Python :: Python NumPy transpose Function Syntax 
Python :: bad request 400 heroku app 
Python :: get legend lables and handles from plot in matplotlib 
Python :: datatime add time in float 
Python :: re.search 
Python :: tensorflow euclidean distance 
Python :: pytorch torchaudio torchvision cu113 
Python :: python remove multiple element from list by index 
Python :: pandas check length of string 
Python :: check whether number is even or odd 
Python :: jacobi iteration method python 
Python :: python using list as dictionary key 
Python :: node 14 alpine add python 
Python :: create table numpy 
Python :: python ip camera 
Python :: Finding if 2 consecutive numbers in a list have a sum equal to a given number 
Python :: how to take an input in python 
Python :: how to round a number up in python 
Python :: how to pre populate field flask wtforms 
Python :: python cassandra 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =