Text processing line --- have irregular spaces between each treatment to {{}}

The average age of the number of sectors Remarks No. 
1 python 30 26 Single Dog
2 Linux 26 30 did not target
3 Operations 20 24 more girls



lst = []
with open("a1.txt", mode="r", encoding="utf-8") as f:
first = f.readline().strip().split(" ")
lst1 = []
for le in first:
if le != "":
lst1.append(le)
for line in f:
dic ={}
s = line.strip().split(" ")
lst2 =[]
for i in s:
if i != "":
lst2.append(i)
for j in range(len(lst1)):
dic[lst1[j]] = lst2[j]
lst.append(dic)
print(lst)


Guess you like

Origin www.cnblogs.com/hadibingjing/p/11071891.html