如何创建列表列表 [英] how to create a list of lists
本文介绍了如何创建列表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Python代码每次循环都会生成一个列表:
My Python code generates a list everytime it loops:
list = np.genfromtxt('temp.txt', usecols=3, dtype=[('floatname','float')], skip_header=1)
但是我想保存每个-我需要一个列表列表吗?
But I want to save each one - I need a list of lists right?
所以我尝试了:
list[i] = np.genfromtxt('temp.txt', usecols=3, dtype=[('floatname','float')], skip_header=1)
但是Python现在告诉我未定义列表".我不确定如何定义它.此外,列表列表是否与数组相同?
But Python now tells me that "list" is not defined. I'm not sure how I go about defining it. Also, is a list of lists the same as an array??
谢谢!
推荐答案
使用附加方法,例如:
lst = []
line = np.genfromtxt('temp.txt', usecols=3, dtype=[('floatname','float')], skip_header=1)
lst.append(line)
这篇关于如何创建列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文