Write a Python program to move all spaces to the front of a given string in single traversal.


Topic: Write a Python program to move all spaces to the front of a given string in single traversal.

Solution

def moveSpaces(str1): 
    no_spaces = [char for char in str1 if char!=' ']   
    space= len(str1) - len(no_spaces)
    result = ' '*space    
    return result + ''.join(no_spaces)



List all Python Programs