Remove spaces from a given string | Function to remove all spaces from a given string ; To keep track of non - space character count ; Traverse the given string . If current character is not space , then place it at index 'count++ ; Utility Function ; Driver program
def removeSpaces ( string ) : NEW_LINE INDENT count = 0 NEW_LINE list = [ ] NEW_LINE DEDENT ' NEW_LINE INDENT for i in xrange ( len ( string ) ) : NEW_LINE INDENT if string [ i ] != ' ▁ ' : NEW_LINE INDENT list . append ( string [ i ] ) NEW_LINE DEDENT DEDENT return toString ( list ) NEW_LINE DEDENT def toString ( List ) : NEW_LINE INDENT return ' ' . join ( List ) NEW_LINE DEDENT string = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " NEW_LINE print removeSpaces ( string ) NEW_LINE