python - Split a string into N equal parts? -
this question has answer here:
- split string sized chunks 5 answers
i have string split n equal parts.
for example, imagine had string length 128 , want split in 4 chunks of length 32 each; i.e., first 32 chars, second 32 , on.
how can this?
import textwrap print textwrap.wrap("123456789", 2) #prints ['12', '34', '56', '78', '9']
note: careful whitespace etc - may or may not want.
"""wrap single paragraph of text, returning list of wrapped lines. reformat single paragraph in 'text' fits in lines of no more 'width' columns, , return list of wrapped lines. default, tabs in 'text' expanded string.expandtabs(), , other whitespace characters (including newline) converted space. see textwrapper class available keyword args customize wrapping behaviour. """
Comments
Post a Comment