Splitting a string using space delimiters and a maximum length

后端 未结 3 1057
遇见更好的自我
遇见更好的自我 2021-01-11 21:44

I\'d like to split a string in a similar way to .split() (so resulting in a list) but in a more intelligent way: I\'d like it to split it into chunks that are u

3条回答
  •  -上瘾入骨i
    2021-01-11 22:14

    >>> import textwrap
    >>> string = 'A string with words'
    >>> textwrap.wrap(string,15)
    ['A string with', 'words']
    

提交回复
热议问题