Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Comparing Sets with issubset() Function in python

# The issubset() function can be used to determine if a set is a subset of another
# set. Let’s see an example:

mySet = {2, 4}
mySet2 = {1, 2, 3, 4, 5}
print(mySet.issubset(mySet2))

# Output:
# True

# Looking at the example above, we can tell by the output that mySet is a subset
# of mySet2, meaning that all the values in mySet is also within mySet2.
# Let’s see what happens if we check to see if mySet2 is a subset of mySet:

mySet = {2, 4}
mySet2 = {1, 2, 3, 4, 5}
print(mySet2.issubset(mySet))

# Output:
# False

# Looking at the example above, we can verify that mySet2 is not a subset of mySet
# as not all of it’s values are in mySet.
Source by liu-111.medium.com #
 
PREVIOUS NEXT
Tagged: #Comparing #Sets #Function #python
ADD COMMENT
Topic
Name
8+4 =