用于知识目的
Input:
[[[[[], [], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
Output:
[[[[[], [x], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
如何将x添加到列表列表的第二个列表中?
答案 0 :(得分:3)
只需使用嵌套索引(适用于嵌套列表):
original_list[0][0][0][1].append(x) # 2nd of 1st of 1st of 1st.
假设x
是一个变量。否则,请使用字符串'x'
。
演示:
>>> original_list = [[[[[], [], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
>>> original_list[0][0][0][1].append('x')
>>> original_list
[[[[[], ['x'], []]], ['trynda'], [[[], [], []]]], ['cait'], [[[[], [], []]], ['veigar'], [[[], [], []]]]]
^
答案 1 :(得分:1)
my_list[0][0][0][1].append(x)
假设x
包含值。如果是字符串,您需要'x'
。