파이썬 한 줄로 목록에있는 항목이 다른 목록에 있는지 확인 하시겠습니까?
목록이 있다고 가정 해 보겠습니다. a=[1,2,3] And I want to know if at least one of the numbers in it exist in another list, like this one: b=[4,5,6,7,8,1] In other words, I want to know if 1,2 or 3 exist(s) in list b. 이제 다음과 같이 할 수 있습니다. def func(a, b): for i in a: if i in b: return True return False 그러나 일을 정리하기 위해 한 줄에 넣는 방법이 있습니까? 해결 방법 이를 수행하는 방법에는 여러 가지가 있습니다. 가장 직접적인 번역은 다음과 같습니다. any_in = lambda a, b: an..
2021. 2. 16.