处理文本

name:apple price:10 amount:3 year:2012
name:tesla price:100000 amount:1 year:2013




lst = []
with open("a1.txt",mode="r",encoding="utf-8") as f:
for line in f:
dic ={}
s = line.strip().split(" ")
for i in s:
a,b=i.split(":")
dic[a] = b
lst.append(dic)
print(lst)
posted @ 2019-06-23 09:03  冰灬荷  阅读(114)  评论(0编辑  收藏  举报