Created
September 9, 2014 09:45
-
-
Save neotheicebird/bd7bdb47b8e4d424d163 to your computer and use it in GitHub Desktop.
Remove white spaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# courtesy: http://stackoverflow.com/questions/8270092/python-remove-all-whitespace-in-a-string | |
# remove leading spaces | |
sentence = ' hello apple' | |
sentence.strip() | |
# >>> 'hello apple' | |
# remove all spaces | |
sentence = ' hello apple' | |
sentence.replace(" ", "") | |
# >>> 'helloapple' | |
# Remove duplicate spaces between words | |
sentence = ' hello apple' | |
" ".join(sentence.split()) | |
# >>> 'hello apple' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment