作者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://www.ptt.cc/bbs/Python/M.1599980905.A.5C2.html
推 oneonesix: 感謝分享 09/14 06:10
推 jlhc: index time complexity is O(n) ... 09/14 14:20