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