我在Python中找到了一个列表:
['Some', 'text', ':', 'And', 'some', 'other', 'text']我想要一个在:之前拆分列表的函数,例如:
['Some text :', 'And some other text'].实现这一目标的最佳方法是什么?耽误您时间,实在对不起。
发布于 2021-12-14 18:13:22
你可以试试这个:
lst = ['Some', 'text', ':', 'And', 'some', 'other', 'text']
ans = " ".join(lst).split(":")
ans[0], ans[1] = ans[0]+":", ans[1].lstrip()
print(ans)输出:['Some text :', 'And some other text']
https://stackoverflow.com/questions/70353581
复制相似问题