Python: move spaces to the front of a given string

move spaces to the front of a given string

write a python program to move spaces to the front of a given string.

Program:-

def move_Spaces_front(str1):
noSpaces_char = [ch for ch str1 if ch!= ' ']
spaces_char = len(str1) - len(nospaces_char)
result = ' '*spaces_char
result = '"'+result + ''.join(nospaces_char)+'"'
return(result)

print(move_spaces_front("sirfpadhai . in "))
print(move_spaces_front("   sirfpadhai.in "))

Output:-

"     sirfpadhai.in"
"     sirfpadhai.in"

flowchart:-

Previous articlePython fundamentals (python fundamentals free course)
Next articlePalindrome Program in Java in Hindi

LEAVE A REPLY

Please enter your comment!
Please enter your name here