I need to split strings of data using each character from string.punctuation and string.whitespace as a separator.
string.punctuation
string.whitespace
Furthermore, I need for the
from itertools import chain, cycle, izip s = "Now is the winter of our discontent" words = s.split() wordsWithWhitespace = list( chain.from_iterable( izip( words, cycle([" "]) ) ) ) # result : ['Now', ' ', 'is', ' ', 'the', ' ', 'winter', ' ', 'of', ' ', 'our', ' ', 'discontent', ' ']