반응형
any = 조건이 하나라도 맞으면 참
all = 조건이 모두 같아야 참
l1 = [1, 2, 3, 4]
put = 3
if any(put == i for i in l1): # 하나라도 참이면 참을 반환
print(f"{put} exists in l1")
else:
print(f"No exists")
l2 = [2, 2, 2, 2]
put = 2
if all(put == i for i in l2): # 모두 참이여야 참을 반환
print(f"{put} is the only element in l2")
else:
print(f"{put} No exists")
출력
exists in l1
is the only element in l2
반응형
'개발 Tools > 파이썬_개념' 카테고리의 다른 글
차원의 저주 (Curse of Dimensionality) & 매니폴드 가정 (manifold assumption) (0) | 2021.11.24 |
---|---|
파이썬 시간 복잡도 (Big-o, 빅오) (2) | 2021.10.17 |
파이썬 삼항 연산자, 맴버 연산자, 식별 연산자 (in, not in , is, is not) (0) | 2021.10.17 |
파이썬 집합(set) (삭제, 수정, 추가, 함축, 연산) (0) | 2021.09.17 |
파이썬 딕셔너리(dictionary)(수정, 함축, 삭제, 삽입, 변환) (0) | 2021.09.17 |
댓글