Python: Initialize a list of lists to a certain size,(Python:将列表列表初始化为一定大小,)
问题描述
我正在尝试初始化big_list",这是一个包含列表的列表,我们提前知道big_list"中将有 200 个列表,并且每个列表将只包含字符串或不包含任何内容,稍后在程序中将有一个循环,将(一次或多次)附加到这些列表中的特定数量.
I'm trying to initialize 'big_list', which is a list containing lists, and we know in advance that there will be 200 lists within 'big_list', and that each list will contain only strings or nothing, and that later in the program there will be a loop that appends(one or more times) to only a certain number of those lists.
有没有最简单的方法来解决这个问题?
Is there a simplest way to go about this?
推荐答案
你可以使用列表推导例如:
You can use list comprehension for example:
big_list = [[] for _ in range(200)]
这将创建一个包含 200 个不同列表的列表.
That will create a list containing 200 different lists.
这篇关于Python:将列表列表初始化为一定大小,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python:将列表列表初始化为一定大小,


基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01