I want to display text on a scrollable display with a width of 16 characters. To improve readability, I want to flip through the text, but not just breaking every 16. character, I rather want to split words or punctuation into each end before the limit of 16 characters exceeds.
Example:
text = 'Hello, this is an example of text shown in the scrolling display. Bla, bla, bla!'
this text should be converted to a list of lines with a maximum of 16 characters
result = ['Hello, this is ', 'an example of ', 'text shown in ', 'the scrolling ', 'display. Bla, ', 'bla, bla!']
I started with regex re.split('(\W+)', text) to get a list of each element (word, punctuation), but I can't combine them.
Can you help me or at least give me some advice?
Thanks!
source share