Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将列表插入到包含多个列表的列表中_Python_List_Add - Fatal编程技术网

Python 将列表插入到包含多个列表的列表中

Python 将列表插入到包含多个列表的列表中,python,list,add,Python,List,Add,以知识为目的 Input: [[[[[], [], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]] Output: [[[[[], [x], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]] 如何将x添加到列表

以知识为目的

Input:

    [[[[[], [], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]

Output:

    [[[[[], [x], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
如何将x添加到列表的第二个列表中

只需使用嵌套索引(适用于嵌套列表):

假设
x
是一个变量。否则,请使用字符串,即
'x'

演示:

只需使用嵌套索引(适用于嵌套列表):

假设
x
是一个变量。否则,请使用字符串,即
'x'

演示:

假设
x
包含一个值。如果是字符串,则需要
'x'


假设
x
包含一个值。如果它是一个字符串,则需要
'x'

切勿将'list'用作变量名,因为它是python保留名。@尽管它不是内置函数,但它是类型,如果希望完全精确=),它既是类型又是内置函数。在变量名选择不当的情况下,我可能会覆盖内置函数,而不会使用“list”作为变量名,因为它是python保留名称。@如果你想完全精确=,它不是内置函数,而是类型。它既是类型又是内置函数。在变量名选择不当的情况下,我会覆盖内置函数
original_list[0][0][0][1].append(x)  # 2nd of 1st of 1st of 1st.
>>> original_list = [[[[[], [], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
>>> original_list[0][0][0][1].append('x')
>>> original_list
[[[[[], ['x'], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
          ^
my_list[0][0][0][1].append(x)