Split A String Every N Words Into Smaller Strings
Situation: I have a chunk of text that I want to break down into smaller strings. After every n Words. text = 'This is a small example Text, showcasing my desired output.' Should
Solution 1:
Try this:
text = 'This is a small example Text, showcasing my desired output.'
text = text.split()
n = 4
[' '.join(text[i:i+n]) for i in range(0,len(text),n)]
Post a Comment for "Split A String Every N Words Into Smaller Strings"