- [Instructor] On line 1, 2, 3,
there are three groups defined as group1, group2, group3.
Now, how would you determine if group1
is a subset of group2?
For group1 to be subset of group2,
all elements of group1 should be present in group2.
So let us see how we can find that out.
We can do result is equal to group1 is subset of group2.
And then let us print the result.
python3 subset.py.
The result is false.
All elements of group1 are not present in group2.
That is why group1 is not a subset of group2.
We can represent the same thing using a Venn diagram.
Here is a Venn diagram for subset method.
Subset method returns true
if one set is subset of another, else returns false.
Another way of solving the same problem is using operator.
So what we can do is group1 less than/equal to group2.
That means group1 is a subset of group2.
Now we can check the output.
python3 subset.py.
And you can see result from both the methods is false.
For checking whether one set is subset of another,
you can use a subset method
or the operator less than/equal to.