我在递归嵌套列表的问题上有些困惑。问题是:需要定义一个过程来访问任意深度的嵌套列表。它将接受一个嵌套列表和一个索引,并返回该索引处的列表部分。从给定函数中,递归查找给定索引处的值。
例如
这里有一个更好的可视化表示。要选择其中的元素9,我们需要做一些类似于nested[3][1]的操作。
nested = \ [[[1, 2], 3], [4, [5, 6]], 7, [8, 9, 10]]
recursive_func(nested_list, [3,1]) #recursive function definition, the second argument is the index at which the data needs to be retrieved.
>>> 9 #so given the function an index of [3,1] would return 9
Any help to point me in the right direction would be grateful