1
00:00:05,120 --> 00:00:09,520
The set difference is the set of all items 
that are in one set, but not in the other. 

2
00:00:09,520 --> 00:00:14,400
I'll start with an example, using our odds 
and primes sets from a couple of videos ago. 

3
00:00:14,400 --> 00:00:19,280
I've created a new Python file called 
set_diference.py. Pause the video while 

4
00:00:19,280 --> 00:00:24,847
you create your file, and copy the first 
12 lines from set_intersection.py into it: 

5
00:00:25,360 --> 00:00:31,023
Ok. If we want a set of odd numbers that aren't 
prime, we take the difference of the 2 sets. 

6
00:00:31,200 --> 00:00:35,548
I'll use the difference method first, then 
we'll do the same thing using the operator. 

7
00:00:43,920 --> 00:00:48,650
Line 14 will remove all members of 
primes from the odds set. Run the program 

8
00:00:50,880 --> 00:00:55,398
and we're left with odd numbers that aren't 
prime. That's the last line of the output. 

9
00:00:55,440 --> 00:00:59,280
Prime numbers, in case you don't 
know, are integers greater than 1, 

10
00:00:59,280 --> 00:01:02,880
that aren't the product of two 
smaller numbers. In school, 

11
00:01:02,880 --> 00:01:06,726
they're often described as numbers that 
are only divisible by themselves and 1. 

12
00:01:06,726 --> 00:01:11,451
They're very important in programming, in 
areas such as security and cryptography. 

13
00:01:12,456 --> 00:01:14,621
Using the operator gives the same result:

14
00:01:21,782 --> 00:01:23,680
Run the program again,

15
00:01:26,091 --> 00:01:30,000
and we get the same set.
Just like with numerical subtraction,

16
00:01:30,000 --> 00:01:34,561
set difference is non-commutative. If we 
perform the operation the other way round,

17
00:01:34,561 --> 00:01:37,251
we get a different result. Let's see that:

18
00:01:44,529 --> 00:01:45,910
Run the program again.

19
00:01:48,689 --> 00:01:52,162
This time, we've removed the odd 
numbers from the set of primes.

20
00:01:52,656 --> 00:01:56,323
odds was the set of odd numbers less 
than 50, so there are no odd numbers, 

21
00:01:56,323 --> 00:02:01,905
less than 50, in the result.
In fact, the only value less than 50 is 2. 

22
00:02:02,175 --> 00:02:05,564
2 is counted as a prime 
number – it's the only even prime number. 

23
00:02:06,479 --> 00:02:09,600
Alright. That's the set difference 
operation, which we've seen using 

24
00:02:09,600 --> 00:02:14,640
both the method, and the operator.
In the next video, we'll use an earlier example, 

25
00:02:14,640 --> 00:02:19,520
to see a practical application for set difference.
See you in the next video.

