If I had the sentence sentence = 'There is light!'
and I was to split this sentence with mysentence = sentence.split()
, how would I have the output as 'There, is, light, !'
of print(mysentence)
? What I specifically wanted to do was split the sentence including all punctuation, or just a list of selected punctuation. I got some code but the program is recognizing the characters in the word, not the word.
out = "".join(c for c in punct1 if c not in ('!','.',':'))
out2 = "".join(c for c in punct2 if c not in ('!','.',':'))
out3 = "".join(c for c in punct3 if c not in ('!','.',':'))
How would I use this without recognizing each character in a word, but the word itself. Therefore, the output of "Hello how are you?"
should become "Hello, how, are, you, ?"
Any way of doing this