Python- List 비교

GYO·2021년 8월 3일
0
post-thumbnail
a = list(range(10))
b = [3,8,10,12]

print('a:',a,'\nb:',b)

print()

합집합 = set(a) | set(b)
print("합집합 :", 합집합)

교집합 = sorted(set(a) & set(b))
print("교집합 :", 교집합)
print("sorted 후의 타입은:", type(교집합))

차집합 = set(a).difference(set(b))
차집합2 = set(a) - set(b)
print("차집합 :",차집합)

print(17 not in a) 
print(19 in a)


'''
<리스트끼리 비교하는 방법 (원소)>
1. if 조건문을 사용한다
2. set 형태로 바꾼 뒤 비트연산한다 (| = and , & = or , - = dif  )
'''


참조 : https://appia.tistory.com/101
환경 : https://www.programiz.com/python-programming/online-compiler/

profile
Hope that fully-automated society comes true

0개의 댓글