Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_handle(self):
- sentence = ' hello apple '
- sentence.strip()
- sentence = ' hello apple'
- sentence.strip()
- >>> 'hello apple'
- sentence = ' hello apple'
- sentence.replace(" ", "")
- >>> 'helloapple'
- sentence = ' hello apple'
- " ".join(sentence.split())
- >>> 'hello apple'
- sentence = sentence.replace(' ', '')
- sentence = ''.join(sentence.split())
- import re
- pattern = re.compile(r's+')
- sentence = re.sub(pattern, '', sentence)
- sentence = sentence.strip()
- sentence = re.sub(r"s+", "", sentence, flags=re.UNICODE)
- import string
- ' hello apple'.translate(None, string.whitespace)
- >> " foo bar ".strip()
- "foo bar"
- ' hello ntapple'.translate( { ord(c):None for c in ' ntr' } )
- import re
- sentence = ' hello apple'
- re.sub(' ','',sentence) #helloworld (remove all spaces)
- re.sub(' ',' ',sentence) #hello world (remove double spaces)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement