【问题标题】:Unknown number of nested list in python 3python 3中未知数量的嵌套列表
【发布时间】:2018-01-08 18:16:01
【问题描述】:

如何创建嵌套列表? 例如,有一个列表 lines[None]*int(nl) 其中 nl 是行数,从用户获取的输入,并且在 lines[] 中我想创建多个列表来保存不同行的数字。

【问题讨论】:

  • 请提供示例输入输出
  • 我们也是“代码爱好者”——请提供一些代码,或示例的输入和输出到澄清您的“列表”和用户输入是什么。而且您想创建多个列表...您是什么意思“其中包含不同行的数字。”?

标签: python list python-3.x nested


【解决方案1】:

以下代码向您展示了如何将列表添加到列表中。我假设这就是你想要的

list_example = []
# this will be your base list
print (list_example)
#now lets add a sub list
list_example.append([])
print (list_example)
#now lets add a list to that list
list_example[0].append([])

【讨论】:

    猜你喜欢
    • 2019-03-07
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 2014-10-12
    • 2021-05-06
    相关资源
    最近更新 更多