【发布时间】:2020-08-31 00:45:28
【问题描述】:
我一直致力于 WhatsApp Chat 的 python 数据可视化项目。我有一个这样的字符串。
line = '[14/11/18, 2:47:26 PM] Chaitanya: Yeah, Lets go to the movies to night'
我想把它分解成这样。
['[14/11/18, 2:47:26 PM]', 'Chaitanya: Yeah, Lets go to the movies to night']
我尝试过使用split() 函数,但我似乎无法得到完全相同的东西。此外,第一次字段会有所不同,因此该字段的长度可能每次都不相同。
我会得到一些帮助。谢谢。
【问题讨论】:
-
也许是
[line[:line.index(']')+1], line[line.index(']')+2:]]
标签: python python-3.x string datetime