创建具有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)

相关内容

  • 没有找到相关文章

最新更新