作者HenryLiKing (亨利王子)
看板Python
标题Re: [问题] 多个list快速比对
时间Sun Sep 13 15:08:22 2020
原文吃光光
A = [1, 2, 3, 4]
B = [5, 6, 7, 8]
C = [1, 3, 4, 5, 7]
for c in C:
try:
print(B[A.index(c)])
except:
pass
Result:
5
7
8
如果是我的话我会这样写~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.138.155.196 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1599980905.A.5C2.html
1F:推 oneonesix: 感谢分享 09/14 06:10
2F:推 jlhc: index time complexity is O(n) ... 09/14 14:20