繁体   English   中英

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

[英]How to print all element of the list and not only the last one?

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

有我的代码:

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....]

请帮助我,我坚持太久了..

代替

result = re.findall….

利用

result += re.findall…

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM