[英]Using variables as index on list
I have two lists: 我有两个清单:
List1 = [1, 3, 6, 8, 1, 61, 89, ...] # This is how List1 is declared
List2[1][3][6][8][1][61][89][...] # This is how I want to access data from List2
List1
is a one one-dimensional list with undefined size (can have 1, 2 or infinite items) List1
是一个未定义大小的一维列表(可以包含1个,2个或无限个项目)
List2
is a multi-dimensional (nested) list (can be 2d or 3d or infinite) List2
是多维(嵌套)列表(可以是2d或3d或无限)
I wanted to use the lists like this List2[List1[0]][List1[1]][List1[...]]
; 我想使用类似List2[List1[0]][List1[1]][List1[...]]
; I want to access the data in List2
using the data from List1
. 我想使用List1
的数据访问List2
中的数据。
I tried the following but I got an error 我尝试了以下操作,但出现错误
len(List2[List1])
How can I access List2
's data by using the indexes in List1
? 如何使用List1
的索引访问List2
的数据?
len(List2[List1])
: You are trying to index a List2
using List1
while indexing in lists is done using integers. len(List2[List1])
:您尝试使用List1
为List2
编制索引,而列表中的索引是使用整数完成的。
Try: len(List2[List1[0]])
尝试: len(List2[List1[0]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.