Python:将清单清单初始化为一定大小, [英] Python: Initialize a list of lists to a certain size,

查看:106
本文介绍了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.

有最简单的方法吗?

推荐答案

您可以使用列表理解功能,例如:

You can use list comprehension for example:

big_list = [[] for _ in range(200)]

这将创建一个包含200个不同列表的列表.

That will create a list containing 200 different lists.

这篇关于Python:将清单清单初始化为一定大小,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆