Python ProgrammingPython Programming

How to split a string into a list?

import string


text = "Oh, you can't help that, said the Cat: we're all mad here. I'm mad. You're mad."
thelist = [word.strip(string.punctuation) for word in text.split()]
print(thelist)

line = "a sentence with a few words"
print(line.split())
Output
['Oh', 'you', "can't", 'help', 'that', 'said', 'the', 'Cat', "we're", 'all', 'mad', 'here', "I'm", 'mad', "You're", 'mad']
['a', 'sentence', 'with', 'a', 'few', 'words']