小编nar*_*nan的帖子

与另一个列表进行比较,确定列表中所有元素的索引

例如我有一个列表A

A = [100, 200, 300, 200, 400, 500, 600, 400, 700, 200, 500, 800]
Run Code Online (Sandbox Code Playgroud)

我有清单B

B = [100, 200, 200, 500, 600, 200, 500]
Run Code Online (Sandbox Code Playgroud)

我需要确定元素的索引BA

我试过了:

list_index = [A.index(i) for i in B]
Run Code Online (Sandbox Code Playgroud)

它返回:

[0, 1, 1, 5, 6, 1, 5]
Run Code Online (Sandbox Code Playgroud)

但我需要的是:

[0, 1, 3, 5, 6, 9, 10]
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

python python-3.x

16
推荐指数
1
解决办法
691
查看次数

标签 统计

python ×1

python-3.x ×1