Is there a way to take a string that is 4*x
characters long, and cut it into 4 strings, each x
characters long, without knowing the length of the string?
For example:
JavaScript
x
5
1
>>>x = "qwertyui"
2
>>>split(x, one, two, three, four)
3
>>>two
4
'er'
5
Advertisement
Answer
JavaScript
1
5
1
>>> x = "qwertyui"
2
>>> chunks, chunk_size = len(x), len(x)//4
3
>>> [ x[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
4
['qw', 'er', 'ty', 'ui']
5