如何打印列表中的所有元素,而不仅仅是最后一个?

2024-10-04 05:19:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个脚本,允许我通过循环提取所有浮点数并将它们放入一个列表中,然后显示包含所有提取浮点数的列表,除了在我的脚本中只考虑每个列表的最后一个数字,而我希望显示所有数字。怎么做

这是我的代码:

final_result = []
result = []
k = listFps
k = 0

while k < len(listFps):
    with open(listFps[k], 'r') as f:
        #
        statList = f.readlines()
        statList = [x.strip() for x in statList]
        for line in statList:
            if (re.search("=", str(line))):
                if (re.search('#IND', str(line))):
                    print("ok")
                else:
                    result =re.findall("=\s*?(\d+\.\d+|\d+)", str(line))

                    print (" ca c result " ,result)

     numberList = [float(q) for q in result]
     print("ca c number list :",numberList)

     k+=1

它只打印我列表中的最后一个元素,如下所示:

[59.889]
[60.874]

等等。。 但我实际上想要一个包含所有元素的列表:

[59.889,60.874....]

请帮帮我,我被困太久了


Tags: inre脚本列表forsearchifline