This post contains a total of 10+ Python Blank Space Remover Program Examples with Source Code. All these Blank Space Remover Programs are used to remove Blank / White Space from Strings, and these programs are made using Python.
You can use the source code of these examples with credits to the original owner.
Related Posts
Python Blank Space Remover Programs
1. By David Ashton
Made by David Ashton. A single line Python program to remove blank space from an input string. Source
demo text demotext
print("".join(input().split()))
2. By Ona Nixon
Made by Ona Nixon. Basic program to remove white space from a string. Source
qw er ty qwerty
str= input()
new=str.replace(" ", "")
print(new)
3. By Janusz Bujak
Made by Janusz Bujak. Python program with multiple ways to remove white / blank space from a string. Source
Hello World HelloWorld HelloWorld
s = "Hello World"
print(s)
print()
print("".join(s.split()))
print(*list(s.split()), sep="")
print("".join(c if c!=" " else "" for c in s))
print(*list(c if c!=" " else "" for c in s), sep="")
print(*filter(lambda x:x!=' ',s),sep='')
[print(i,end='') for i in s if ord(i) not in [9,10,11,12,13,32]]
[print(i,end='') for i in s if not i.isspace()]
print()
(print(''.join(map((lambda x:'' if x==' ' else x),s))))
print(__import__("re").sub(r"\s+", "", s), sep="")
print(s.translate({ord(' '):None}))
print("".join(i for i in list(s) if i.strip()))
print("".join(v for v in dict(enumerate(list(s))).values() if v != " "))
import re
print(re.sub(" ","",s))
class RemoveSpaceFromString:
def __init__(self,string):
self.string = string
def doit(self):
val = self.string.split()
lav = "".join(val)
print(lav)
a = RemoveSpaceFromString(s)
a.doit()
print(s.replace(" ",""))
4. By Barracoder
Made by Barracoder. Source
x y z xyz
def clean_str(string):
return string.replace(" ","")
w = input()
print(clean_str(w))
5. By StraMa
Made by StraMa. Simple Program to take a string as input and output it without spaces. Source
a b c abc
x=""
def rimuovi_spazi(x):
x=input()
if x == "":
print("You have not written anything!")
return x.split()
print("".join(rimuovi_spazi(x)))
6. By Niki
Made by Niki. Python program with two methods to remove empty space from a string. Source
s i x six
#Solution 1
inp=input()
print("".join(inp.split()))
#==========================
#Solution 2
def withoutspace(a):
return a.replace(" ", "")
print(withoutspace(inp))
7. By Niloufar Kashanian
Made by Niloufar Kashanian. Program to remove empty space from a string and replace it with hyphen. Source
Enter string: a a Modified string: a-a
string=input("Enter string:")
string=string.replace(' ','-')
print("Modified string:")
print(string)
8. By Eduardo Petry
Made by Eduardo Petry. Another single line python program to remove empty space from a text and number string. Source
1 1 1 111 a b c abc
print((lambda s: ''.join(s.split()))(input()))
9. By Win Htay
Made by Win Htay. Source
de mo demo
st1 = input()
st2 = st1.split()
print("".join(st2))
10. By Lothar
Made by Lothar. Python program to remove blank space from string using translate. Source
Please enter a sentence: Input: te xt Output: text
transltbl = {' ': None}
inpstr = input('Please enter a sentence: ')
tr_table = str.maketrans(transltbl)
finstr = inpstr.translate(tr_table)
print(f'\nInput: \n{inpstr}')
print(f'Output: \n{finstr}')
11. By SergeR
Made by SergeR. Empty space remover program made using Python Reduce. Source
t e x t text
from functools import reduce
def remove_spaces(string):
# Of course there is a simpler but less interesting way: return string.replace(' ', '')
cond = lambda x, y: x + y if y != ' ' else x
return reduce(cond, string)
inpt1 = 'he llo fri end'
inpt2 = input()
res1 = remove_spaces(inpt1)
res2 = remove_spaces(inpt2)
print(f'{inpt1} -> {res1}')
print(f'{inpt2} -> {res2}')