如何从该文本文件中获取如下词典:
[Fri Aug 20]
shamooshak 4-0 milan
Tehran 2-0 Ams
Liverpool 0-2 Mes
[Fri Aug 19]
Esteghlal 1-0 perspolise
Paris 2-0 perspolise
[Fri Aug 20]
RahAhan 0-0 milan
[Wed Agu 11]
Munich 3-3 ABC
[Wed Agu 12]
RM 0-0 Tarakto
[Sat Jau 01]
Bayern 2-0 Manchester
我尝试过列表理解,对于带有枚举函数的循环。但我无法建立这个列表。你知道吗
我想要的词典是:
{'[Fri Aug 20]':[shamooshak 4-0 milan, Tehran 2-0 Ams,Liverpool 0-2 Mes],'[Fri Aug 19]':[Esteghlal 1-0 perspolise,Paris 2-0 perspolise]
。。。等等。你知道吗
假设你的数据是一行行文字。。。你知道吗
编辑:因为您编辑说它是一个文本文件,所以只需包含以下模式
使用正则表达式(
re
模块)和示例文本:它给出了以下字典
d
:我忽略了日期可能会重复,正如mad所指出的那样,为了避免丢失数据,将
for
循环替换为在这里,
for
可以成为救世主输出
相关问题 更多 >
编程相关推荐