Q:

Write a Python program to move spaces to the front of a given string

0

Write a Python program to move spaces to the front of a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

print(move_Spaces_front("w3resource .  com  "))
print(move_Spaces_front("   w3resource.com  "))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now