Python:我如何拆分()每个符号直到到达分隔符号

Python: how do I split() each symbol until reach separator symbol

我有一个字符串:

a = "12356789:10:51:52:53"

因此,我需要这样的列表:

['1','2','3','5','6','7','8','9','10','51','52','53']

在找到 : 分隔符之前,如何一个一个地拆分符号?

你可以试试这个:

list((x:="12356789:10:51:52:53".split(":"))[0]) + x[1:]

不确定这是否是最佳解决方案,但这可行:

a = "12356789:10:51:52:53"
list(''.join(a.split(":")[0])) + a.split(":")[1:]

这样可以吗?

a = "12356789:10:51:52:53"

l1 = a.split(":")
l2 = [c for c in l1[0]]
output = l2 + l1[1:]
output 
In [193]: a = "12356789:10:51:52:53"

In [194]: first_split = a.index(':')

In [195]: a[:first_split].split()
Out[195]: ['12356789']

In [196]: a = "12356789:10:51:52:53"

In [197]: b = list(a[:first_split])
Out[197]: ['1', '2', '3', '5', '6', '7', '8', '9']

In [198]: c = a[first_split+1:].split(':')
Out[198]: ['10', '51', '52', '53']

然后可以合并b+c

一个有趣的小技巧(不推荐用于生产代码:-):

a = "12356789:10:51:52:53"

[*b], *b[len(a):] = a.split(':')

print(b)

输出:

['1', '2', '3', '5', '6', '7', '8', '9', '10', '51', '52', '53']