So I tried using join()
after splitting a string into words and punctuation but it joins the string with a space in between the word and punctuation.
b = ['Hello', ',', 'who', 'are', 'you', '?']
c = " ".join(b)
But that returns:
c = 'Hello , who are you ?'
and I want:
c = 'Hello, who are you?'
Do this after you get the result, not full, but works...
Output:
You could join on the punctuation first:
The
join_punctuation
generator yields strings with any following punctuation already joined on:How abt
Maybe something like:
This adds a space before words in
b
which aren't made up entirely of punctuation.