如何将数字切成三部分

时间:2017-03-24 13:25:38

标签: python python-3.x python-3.6

我如何切割和拆分这样的列表 A = ['105200166','177288399']成 [['105','200','166'],['177','288',399']

1 个答案:

答案 0 :(得分:0)

>>> thelist =  ['105200166', '177288399']
>>> result = []
>>> for item in thelist:
...     tmp = []
...     sets = (len(item) + 2) // 3
...     for i in range(0, sets):
...         start = i * 3
...         end = start + 3
...         tmp.append(item[start:end])
...     result.append(tmp)
...
>>> result
[['105', '200', '166'], ['177', '288', '399']]