1
00:00:05,200 --> 00:00:10,000
I've created a new Python file called 
super_sub.py for these examples. 

2
00:00:10,000 --> 00:00:14,911
A good place to start is with the animals and 
birds sets, that we've just seen in the slides: 

3
00:01:04,560 --> 00:01:08,080
Ok, the slides showed using the 
greater than and less than operators, 

4
00:01:08,080 --> 00:01:11,440
to check if one set is a 
superset or subset of another. 

5
00:01:11,440 --> 00:01:14,930
Sets also have a couple of 
methods, and I'll start with those: 

6
00:01:49,440 --> 00:01:53,304
The issubset method will return True if birds is 
a subset of animals. 

7
00:01:53,304 --> 00:01:58,694
issuperset returns True if animals is a superset of birds.
Run the program: 

8
00:02:00,800 --> 00:02:04,960
and we get the expected results. 
birds is a subset of animals, 

9
00:02:04,960 --> 00:02:09,600
which means that animals is a superset of birds.
If we do that the other way round, 

10
00:02:09,600 --> 00:02:11,938
we should get False:

11
00:02:29,683 --> 00:02:32,095
Run the program again:

12
00:02:34,320 --> 00:02:39,760
and birds isn't a superset of animals. There's 
nothing surprising about these results. 

13
00:02:39,760 --> 00:02:42,339
Let's use the operators to check:

14
00:02:56,551 --> 00:03:04,160
I haven't printed any text this time, to save time typing.
Run the program: 

15
00:03:04,160 --> 00:03:08,560
and birds is both a subset of animals, 
and a proper subset of animals. 

16
00:03:08,560 --> 00:03:13,200
Note that the issubset and issuperset 
methods check for subsets and supersets. 

17
00:03:13,200 --> 00:03:18,560
They're equivalent to using less than or equal 
to, and greater than or equal to, respectively. 

18
00:03:18,560 --> 00:03:21,920
The methods don't check for 
proper subsets or supersets. 

19
00:03:21,920 --> 00:03:26,190
I'll demonstrate that by creating a new set, and 
checking it against the birds set.

20
00:03:26,331 --> 00:03:30,297
I'll print a row of asterisks first, to separate the output:

21
00:03:51,531 --> 00:03:54,896
Ok, that's the same set as our birds set.

22
00:03:54,896 --> 00:03:58,227
Just to be sure, I'll compare the two sets:

23
00:04:06,192 --> 00:04:07,744
Run the program:

24
00:04:10,160 --> 00:04:13,440
and check that we get True. 
The two sets are equal, 

25
00:04:13,440 --> 00:04:17,920
because they both contain the same elements.
Now we can demonstrate the difference between 

26
00:04:17,920 --> 00:04:20,103
subset and proper subset:

27
00:04:35,651 --> 00:04:43,440
On line 25, we check if garden_birds is a subset of birds.
Line 26 checks if it's a proper subset. 

28
00:04:43,440 --> 00:04:48,228
That means it's a subset, but isn't the same set.
Run the program again: 

29
00:04:50,400 --> 00:04:55,520
Line 25 prints True. garden_birds 
is a subset of birds. 

30
00:04:55,520 --> 00:04:59,840
We've already checked if the sets are equal. 
They are – which means garden_birds isn't 

31
00:04:59,840 --> 00:05:05,682
a proper subset. The output from line 
26 confirms that - we get False printed. 

32
00:05:05,682 --> 00:05:10,160
You can do the same thing with supersets: use 
greater than, and greater than or equal to, 

33
00:05:10,160 --> 00:05:14,400
to check for a superset.
Alright, the last thing we should check, is what 

34
00:05:14,400 --> 00:05:17,196
happens when one set isn't a subset of another.

35
00:05:17,196 --> 00:05:21,000
I'll print another row of asterisks, and create a new set:

36
00:05:51,744 --> 00:05:56,975
The more_birds set contains Budgie, so it can't be a subset of garden_birds.

37
00:05:57,383 --> 00:05:59,920
There's no budgie in garden_birds.

38
00:05:59,920 --> 00:06:06,966
On line 31, I checked if garden_birds is 
a superset of more_birds. Run the program: 

39
00:06:09,040 --> 00:06:11,920
to make sure we get False.
There's not much else to 

40
00:06:11,920 --> 00:06:16,518
say about sets and subsets – not 
without getting all mathematical, anyway.

41
00:06:16,518 --> 00:06:19,600
And if you need to use Python 
for set theory, you've got almost 

42
00:06:19,600 --> 00:06:24,080
everything you need to perform all the set 
operations and tests that set theory uses. 

43
00:06:24,080 --> 00:06:28,160
I said almost, because there's one 
more method that you might find useful. 

44
00:06:28,160 --> 00:06:33,520
Sets also have an isdisjoint method. Sets 
are disjoint if they have no items in common. 

45
00:06:33,520 --> 00:06:38,080
Check out the isdisjoint method, when you 
read through the documentation on sets. 

46
00:06:38,080 --> 00:06:43,440
In the next video, we'll see a practical 
application of checking for subsets and supersets. 

47
00:06:43,440 --> 00:06:47,200
See you in the next video.

