python - Split a string into N equal parts? -


this question has answer here:

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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -