python 读取TXT文档内容 转换为字典


with open("yester.txt","r",encoding="utf-8") as f:
user_dict={}
for userline in f:
userline=str(userline).replace('\n','')
user_dict[userline.split(' ',1)[0]]=userline.split(' ',1)[1]


txt文件:
a ah
a ey
cat k ae t
of ah v
peck p eh k
peppers p eh p er z
peter p iy t er
picked p ih k t
pickled p ih k ah l d
piper p ay p er
the dh ah
the dh iy


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM