以下文件2016_01_22_Reps.txt是我想要放入python dic文件的扩展收缩列表; “can not”:“can not”,“could've”:“could have”,“could've”:“could have”,“did not”:“did not”,“does not”: “不”,“不”,“不”,“没有”,“没有”,“没有”,“没有”,“没有”,“没有”,“我会“:”我会“,”我是“:”我是“,”我有“:”我有“,”不是“:”不是“,”我会“:”我 注意,内容是单个线,而不是多行将文本文件读入dic文件导致不完整的dic文件
我的代码如下。
reps = open('2016_01_22_Reps.txt', 'r')
Reps1dic={}
for line in reps:
x=line.split(",")
a=x[0]
b=x[1]
c=len(b)-1
b=b[0:c]
Reps1dic[a]=b
print (Reps1dic)
前两对收缩的目录如下后输出到Reps1dic停止;
{‘2016_01_22Reps = {“can\’t”:”cannot”‘ : ‘”could\’ve”:”could have’}
说明和解释为什么完整的文件内容没有写入到dic文件将不胜感激。
感谢您的帮助! – RJS