*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).
isdisjoint() can check if the set or frozenset and other
don't have any common elements as shown below:
*Memo:
- The 1st argument is
other
(Required-Type:Iterable):- Don't use
other=
.
- Don't use
<Set>:
A = {10, 20, 30} # set
B = frozenset([40, 50]) # frozenset
C = [30, 40] # list
print(A.isdisjoint(B)) # True
print(A.isdisjoint(C)) # False
<Frozenset>:
A = frozenset([10, 20, 30]) # frozenset
B = {40, 50} # set
C = [30, 40] # list
print(A.isdisjoint(B)) # True
print(A.isdisjoint(C)) # False
issubset() can check if every element in the set or frozenset is in other
as shown below:
*Memo:
- The 1st argument is
other
(Required-Type:Iterable):- Don't use
other=
.
- Don't use
-
<=
can doissubset()
, supportingset
andfrozenset
.
<Set>:
A = {10, 20, 30} # set
B = frozenset([10, 20, 30, 40]) # frozenset
C = [10, 20, 30] # list
D = (10, 20) # tuple
print(A.issubset(B)) # True
print(A.issubset(C)) # True
print(A.issubset(D)) # False
A = {10, 20, 30} # set
B = frozenset([10, 20, 30, 40]) # frozenset
C = frozenset([10, 20, 30]) # frozenset
D = frozenset([10, 20]) # frozenset
print(A <= B) # True
print(A <= C) # True
print(A <= D) # False
<Frozenset>:
A = frozenset([10, 20, 30]) # frozenset
B = {10, 20, 30, 40} # set
C = [10, 20, 30] # list
D = (10, 20) # tuple
print(A.issubset(B)) # True
print(A.issubset(C)) # True
print(A.issubset(D)) # False
A = frozenset([10, 20, 30]) # frozenset
B = {10, 20, 30, 40} # set
C = {10, 20, 30} # frozenset
D = {10, 20} # frozenset
print(A <= B) # True
print(A <= C) # True
print(A <= D) # False
issuperset() can check if every element in other
is 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()
, supportingset
andfrozenset
.
<Set>:
A = {10, 20, 30} # set
B = frozenset([10, 20, 30, 40]) # frozenset
C = [10, 20, 30] # list
D = (10, 20) # tuple
print(A.issuperset(B)) # False
print(A.issuperset(C)) # True
print(A.issuperset(D)) # True
A = {10, 20, 30} # set
B = frozenset([10, 20, 30, 40]) # frozenset
C = frozenset([10, 20, 30]) # frozenset
D = frozenset([10, 20]) # frozenset
print(A >= B) # False
print(A >= C) # True
print(A >= D) # True
<Frozenset>:
A = frozenset([10, 20, 30]) # frozenset
B = {10, 20, 30, 40} # set
C = [10, 20, 30] # list
D = (10, 20) # tuple
print(A.issuperset(B)) # False
print(A.issuperset(C)) # True
print(A.issuperset(D)) # True
A = frozenset([10, 20, 30]) # frozenset
B = {10, 20, 30, 40} # set
C = {10, 20, 30} # set
D = {10, 20} # set
print(A >= B) # False
print(A >= C) # True
print(A >= D) # True
Top comments (0)