subset superset disjoint code example

Example: subset superset disjoint

setA = {1, 2, 3, 4, 5, 6}
setB = {1, 2, 3}

# subset means all elments of setA in setB
setA.issubset(setB)  #False
setB.issubset(setA)  #True

# superset returns true if setA contains all elements from setB
# than it is superset() but here setB is not superset of setA

setB.issuperset(setA) #False
setA.issuperset(setB) #True


# Disjoints returns true if both sets have a null intersection 
# means no same elements

setC = {7,8}
setA.isdisjoint(setB) #False
setA.isdisjoint(setC) #True

Tags:

Misc Example