用python写代码的时候,每一步循环都输出了一行列表,如何才能只保留或显示最后一行列表呢?
问题相关代码:
import os
path="E:\Game"
files=os.listdir(path)
y=[]
for file in files:
position=path+'\'+file
file=open(position)
read=file.read()
count=read.count('1')
fc=count/2500
y.append(fc)
print(y)
结果:
[0.494]
[0.494, 0.5132]
[0.494, 0.5132, 0.5132]
[0.494, 0.5132, 0.5132, 0.5132]
[0.494, 0.5132, 0.5132, 0.5132, 0.5132]
如何使结果只显示最后一行:[0.494, 0.5132, 0.5132, 0.5132, 0.5132]