I am trying to breakup/split a string into words.
def breakup(text):
temp = []
temp = re.split('\W+', text.rstrip())
return [e.lower() for e in temp]
Example Strings:
What's yellow, white, green and bumpy? A pickle wearing a tuxedo
Result:
['what', 's', 'yellow', 'white', 'green', 'and', 'bumpy', 'a', 'pickle', 'wearing', 'a', 'tuxedo']
but when i pass a string like
How is a locksmith like a typewritter? They both have a lot of keys!
['how', 'is', 'a', 'locksmith', 'like', 'a', 'typewritter', 'they', 'both', 'have', 'a', 'lot', 'of', 'keys', '']
I want to parse in a way that it doesn't get empty string in the list.
The string passed will have punctuation etc. Any ideas.