Posts /

2018-05-26 TIL

26 May 2018

Python 과 집합


# 서로소
s1 = {1,2,3}
s2 = {3,4,5}
s3 = {4,5,6}
s4 = {1,2}

s1.isdisjoint(s3)
> True
s1.isdisjoint(s2)
> False

# 부분집합
s1.issubset(s4)
> False
s1 <= s4
> False

s4.issubset(s1)
> True
s4 <= s1
> True
s4 <= s4
> True


Twitter Facebook Google+