SHARE
TWEET

normalise_spaces

a guest Sep 15th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def normalise_spaces(string):
  2.     flg = False
  3.     normalise_string = ""
  4.     for char in string:
  5.         if char != ' ':
  6.             normalise_string += char
  7.             if flg == True: flg = False
  8.         if char == ' ':
  9.             if flg == False:
  10.                 normalise_string += char
  11.                 flg = True
  12.     return normalise_string
  13.  
  14.  
  15. normalise_spaces("   Hello Geeks . Welcome   to  GeeksforGeeks   .    ")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top