简体   繁体   English

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

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

I wrote a script that allows me to extract through a loop all the floating numbers and put them in a list, then display this list with all the extracted floating numbers except that in my script only the last number of each list is taken into account, while I would like all the numbers to be displayed.我编写了一个脚本,允许我通过循环提取所有浮点数并将它们放入一个列表中,然后显示这个列表以及所有提取的浮点数,除了在我的脚本中只考虑每个列表的最后一个数字,而我希望显示所有数字。 how to do it?怎么做?

there is my code:有我的代码:

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

its print me only the last element of my list like this:它只打印我列表的最后一个元素,如下所示:

[59.889]
[60.874]

etc.. But i actually want a list with all element:等等。但我实际上想要一个包含所有元素的列表:

[59.889,60.874....]

Help me please im stuck with it for too long..请帮助我,我坚持太久了..

Instead of代替

result = re.findall….

use利用

result += re.findall…

暂无
暂无

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

相关问题 我想打印列表中添加的所有元素,但它只打印最后一个元素。(Python) - I want to print all the element added in list but it is only printing the last element.(Python) python - 如何从第一个元素开始从列表中一个一个打印元素并递增直到最后一个 - How can I print an element from a list one by one starting by first element and increment until the last one in python 如何使用除最后一个元素之外的一行显示列表中字典的值 - how to print values of dictionary in a list using one line excluding the last element 我如何从我的列表中删除第 N 个元素,直到只剩下一个元素并在 python 中打印剩余的元素 - how do i remove the Nth element from my list until there's only one element remains and print that remaining element in python 如何在每次迭代中只打印列表中的一个元素? - How can I only print one element from the list in each iteration? 如何按最后两个字段拆分列表的每个元素并打印它们? - How to split each element of a list by last two fields and print them? 仅随机播放列表的最后一个元素 - Shuffle only the last element of a list 如何一次打印列表中的一个元素而不结转前一个元素? - How to print one element in a list at a time and not carry forward the previous one? 如果一个列表中的元素存在于 Python 中的另一个列表中,如何打印该元素? - How to print an element from one list if it exists in another list in Python? 如何仅打印前5个和最后5个? - How to print only the first and last 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM