*Memo:
- My post explains set and frozenset functions (1).
- My post explains set and frozenset functions (2).
- My post explains set and frozenset functions (3).
- My post explains set and frozenset functions (4).
- My post explains set and frozenset functions (5).
- My post explains set and frozenset functions (7).
- My post explains a set (1).
- My post explains a frozenset (1).
issubset() can check if all the elements in the set or frozenset are in other as shown below:
*Memo:
- The 1st argument is other(Required-Type:Iterable):- Don't use other=.
 
- Don't use 
- 
<=can doissubset(), supportingsetandfrozenset.
<Set>:
A = {10, 20, 30}
print(A.issubset({10, 20, 30}))     # True
print(A.issubset({10, 20, 40}))     # False
print(A.issubset({10, 20}))         # False
print(A.issubset({10, 40}))         # False
print(A.issubset({10, 20, 30, 40})) # True
print(A.issubset({10, 20, 40, 50})) # False
print(A.issubset(set()))            # False
A = {10, 20, 30}
print(A <= {10, 20, 30})     # True
print(A <= {10, 20, 40})     # False
print(A <= {10, 20})         # False
print(A <= {10, 40})         # False
print(A <= {10, 20, 30, 40}) # True
print(A <= {10, 20, 40, 50}) # False
print(A <= set())            # False
<Frozenset>:
A = frozenset([10, 20, 30])
print(A.issubset(frozenset([10, 20, 30])))     # True
print(A.issubset(frozenset([10, 20, 40])))     # False
print(A.issubset(frozenset([10, 20])))         # False
print(A.issubset(frozenset([10, 40])))         # False
print(A.issubset(frozenset([10, 20, 30, 40]))) # True
print(A.issubset(frozenset([10, 20, 40, 50]))) # False
print(A.issubset(frozenset([])))               # False
A = frozenset([10, 20, 30])
print(A <= frozenset([10, 20, 30]))     # True
print(A <= frozenset([10, 20, 40]))     # False
print(A <= frozenset([10, 20]))         # False
print(A <= frozenset([10, 40]))         # False
print(A <= frozenset([10, 20, 30, 40])) # True
print(A <= frozenset([10, 20, 40, 50])) # False
print(A <= frozenset([]))               # False
issuperset() can check if all the elements in other are in the set or frozenset as shown below:
*Memo:
- The 1st argument is other(Optional-Type:Iterable):- Don't use other=.
 
- Don't use 
- 
>=can doissuperset(), supportingsetandfrozenset.
<Set>:
A = {10, 20, 30}
print(A.issuperset({10, 20, 30}))     # True
print(A.issuperset({10, 20, 40}))     # False
print(A.issuperset({10, 20}))         # True
print(A.issuperset({10, 40}))         # False
print(A.issuperset({10, 20, 30, 40})) # False
print(A.issuperset({10, 20, 40, 50})) # False
print(A.issuperset(set()))            # True
A = {10, 20, 30}
print(A >= {10, 20, 30})     # True
print(A >= {10, 20, 40})     # False
print(A >= {10, 20})         # True
print(A >= {10, 40})         # False
print(A >= {10, 20, 30, 40}) # False
print(A >= {10, 20, 40, 50}) # False
print(A >= set())            # True
<Frozenset>:
A = frozenset([10, 20, 30])
print(A.issuperset(frozenset([10, 20, 30])))     # True
print(A.issuperset(frozenset([10, 20, 40])))     # False
print(A.issuperset(frozenset([10, 20])))         # True
print(A.issuperset(frozenset([10, 40])))         # False
print(A.issuperset(frozenset([10, 20, 30, 40]))) # False
print(A.issuperset(frozenset([10, 20, 40, 50]))) # False
print(A.issuperset(frozenset([])))               # True
A = frozenset([10, 20, 30])
print(A >= frozenset([10, 20, 30]))     # True
print(A >= frozenset([10, 20, 40]))     # False
print(A >= frozenset([10, 20]))         # True
print(A >= frozenset([10, 40]))         # False
print(A >= frozenset([10, 20, 30, 40])) # False
print(A >= frozenset([10, 20, 40, 50])) # False
print(A >= frozenset([]))               # True
isdisjoint() can check if the set or frozenset and other don't have their common elements as shown below:
*Memo:
- The 1st argument is other(Required-Type:Iterable):- Don't use other=.
 
- Don't use 
- 
notkeyword and&can doisdisjoint(), supportingsetandfrozensetbut it's inefficient.
<Set>:
A = {10, 20, 30}
print(A.isdisjoint({40, 50})) # True
print(A.isdisjoint({20, 40})) # False
print(A.isdisjoint(set()))    # True
A = {10, 20, 30}
print(not (A & {40, 50})) # True
print(not (A & {20, 40})) # False
print(not (A & set()))    # True
<Frozenset>:
A = frozenset([10, 20, 30])
print(A.isdisjoint(frozenset([40, 50]))) # True
print(A.isdisjoint(frozenset([20, 40]))) # False
print(A.isdisjoint(frozenset([])))       # True
A = frozenset([10, 20, 30])
print(not (A & frozenset([40, 50]))) # True
print(not (A & frozenset([20, 40]))) # False
print(not (A & frozenset([])))       # True
 

 
    
Top comments (0)