Python - 不同长度的列表列表

标签 python arrays list

我需要创建一个包含两个列表的列表。 有点像

biglist = [list1,list2]

list1 = [1,2,3]
list2 = [4,5,6,7,8]

其中 list1list2 具有不同的长度并且是从文件导入的。

我是通过以下方式做到的:

biglist = []
list1 = #...taken from file. I checked this and it poduces a list exactly how I want it to be: [1,2,3]
biglist.append(list1)

同样适用于 list2

但问题是我得到了

biglist = [array([1,2,3]),array([4,5,6,7,8])]

相对于

biglist = [[1,2,3],[4,5,6,7,8]]

而且我真的不想要array 东西,我更喜欢简单的列表。 如何解决这个问题?

最佳答案

请尝试:

biglist.append(list(list1))
biglist.append(list(list2))

或者如果它们是 numpy 数组

biglist.append(list1.tolist())
biglist.append(list2.tolist())

关于Python - 不同长度的列表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46945466/

相关文章:

c - 通用链表在C中按值打印和添加

python - 在Python3中分析和计算列表列表中的新值

python - pip --cache-dir 与版本范围

Python3 venv : Can env directory be renamed?

python - 如何在 python 中手动处理图像

c++ - 无法弄清楚为什么我的 Print Array 正在替换元素

python - YFinance - tickerData.info 不适用于某些股票

javascript - 将一个数组值复制到其他数组

c++ - 2D vector - 通过搜索删除行

python - Pandas:使用一系列进行列表查找