繁体   English   中英

创建具有名称的空列表列表

[英]Create list of empty lists having name

我对 python 很陌生,正在寻找如何创建一个空列表的列表,其名称比下面显示的更有效

我想列出一些名字。

flattenlist_x1 = []
flattenlist_x2 = []
flattenlist_x3 = []
flattenlist_x4 = []
flattenlist_x5 = []
flattenlist_x6 = []
flattenlist_x7 = []
flattenlist_x8 = []
flattenlist_x9 = []
flattenlist_x10 = []
flattenlist_x11 = []
flattenlist_x12 = []

flattenlist_list = [flattenlist_x1, flattenlist_x2, flattenlist_x3, flattenlist_x4,
                    flattenlist_x5, flattenlist_x6, flattenlist_x7, flattenlist_x8,
                    flattenlist_x9, flattenlist_x10, flattenlist_x11, flattenlist_x12]

因为你希望它有名字,所以使用 dict 怎么样?

flattenlist_list = {}
for i in range(1,13):
    flattenlist_list['flattenlist_x'+str(i)]=[]
print(flattenlist_list)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM