Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re, string
- def removePunctuation(text):
- """Removes punctuation, changes to lower case, and strips leading and trailing spaces.
- Note:
- Only spaces, letters, and numbers should be retained. Other characters should be
- eliminated (e.g. it's becomes its). Leading and trailing spaces should be removed after
- punctuation is removed.
- Args:
- text (str): A string.
- Returns:
- str: The cleaned up string.
- """
- regex = re.compile('[%s]' % re.escape(string.punctuation))
- no_punctuation = regex.sub('', text)
- no_tralling_spaces = no_punctuation.strip()
- lower_case = no_tralling_spaces.lower()
- return lower_case
- print removePunctuation('Hi, you!')
- print removePunctuation(' No under_score!')
- print removePunctuation(' * Remove punctuation then spaces * ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement