小编典典

按长度将字符串拆分为字符串?

python

有没有办法在不知道字符串长度的情况下4*x,将一个x字符长的字符串切成4个字符串,每个字符长?

例如:

>>>x = "qwertyui"
>>>split(x, one, two, three, four)
>>>two
'er'

阅读 224

收藏
2020-12-20

共1个答案

小编典典

>>> x = "qwertyui"
>>> chunks, chunk_size = len(x), len(x)/4
>>> [ x[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
['qw', 'er', 'ty', 'ui']
2020-12-20