【发布时间】:2017-06-19 00:32:29
【问题描述】:
我想比较两个 Python 列表,“A”和“B”,以便我可以找到 A 中的所有元素,它们对应于 B 中的相同数字强>。我想为B 中的每个数字 执行此操作。例如,如果
A = [5, 7, 9, 12, 8, 16, 25]
B = [2, 1, 3, 2, 3, 1, 4]
我想买
[7,16] corresponding to the number 1 of listB
[5, 12] corresponding to the number 2 of listB
[9, 8] corresponding to the number 3 of listB
[25] corresponding to the number 4 of listB
A 和 B 将始终具有相同的长度。
【问题讨论】:
-
不明白这里的逻辑...能否请您提供更多细节?
[7,16] corresponding to the number 1 of listB... 为什么? -
哦,好吧,我明白了:在列表 B 中,
1在第 2 和第 6 位,而列表 A 中这些位置的数字是 7 和 16。