问题遇到的现象和发生背景
想要将文本转成字典,文本形式如下:
'船舶', 96
'中港', 65
'事故', 41
'情况', 34
'安全', 32
'碰撞', 30
'该轮', 29
'水域', 28
问题相关代码,请勿粘贴截图
with open('accident report_fenci_qutingyongci_cipin.txt') as f:
text=[]
for word in f.readlines():
temp=word.strip().split(',')
text.append(temp)
text=dict(text)
运行结果及报错内容
{"'船舶'": ' 96', "'中港'": ' 65', "'事故'": ' 41', "'情况'": ' 34', "'安全'": ' 32', "'碰撞'": ' 30', "'该轮'": ' 29', "'水域'": ' 28'}
我想要达到的结果
{‘船舶’:96,‘中港’:65,‘事故’:41,……}