python split clever looping

Solutions on MaxInterview for python split clever looping by the best coders in the world

showing results for - "python split clever looping"
Gabriele
21 Mar 2018
1text = "hello, this is some text to break up, with some reeeeeeeeeaaaaaaally long words."
2n = 16
3
4words = iter(text.split())
5lines, current = [], next(words)
6for word in words:
7    if len(current) + 1 + len(word) > n:
8        lines.append(current)
9        current = word
10    else:
11        current += " " + word
12lines.append(current)
13
similar questions
queries leading to this page
python split clever looping