WEBVTT

00:00.170 --> 00:01.040
Hello guys.

00:01.040 --> 00:04.160
So we are going to continue the discussion with respect to Python.

00:04.160 --> 00:08.510
And in this video we are going to discuss about a new data structure which is called as sets.

00:08.540 --> 00:11.450
Now what are first of all, we will see the definition of sets.

00:11.450 --> 00:13.970
And we will see a lot of example along with methods.

00:13.970 --> 00:16.280
And what is the importance of sets altogether.

00:16.340 --> 00:22.100
But one of the most common data structures we specifically use sets after probably a list and dictionaries

00:22.100 --> 00:22.880
and tuples.

00:22.880 --> 00:23.330
Right.

00:23.330 --> 00:25.910
So that is the reason why I am covering this data structure.

00:25.910 --> 00:28.100
So we'll be seeing a lot of examples in short.

00:28.310 --> 00:30.800
So first of all let's go ahead with the definition.

00:30.800 --> 00:35.780
So here you can actually see sets are built in data types in Python used to store collection of unique

00:35.780 --> 00:36.380
items.

00:36.380 --> 00:42.230
They are unordered meaning that the elements do not follow a specific order and they do not allow duplicate

00:42.230 --> 00:42.560
elements.

00:42.560 --> 00:44.510
So they are some of the very important points.

00:44.510 --> 00:49.850
So please make sure that before you start any of the lesson, see the definition sets are useful for

00:49.850 --> 00:50.720
membership test.

00:50.750 --> 00:52.250
Eliminating duplicate entries.

00:52.250 --> 00:57.020
Performing mathematical set operations like union, intersection differences and semantic differences.

00:57.050 --> 01:01.500
Now all these things, what we have actually learned, we'll see with the help of practical example.

01:01.530 --> 01:04.740
So first of all, I'll go ahead and make a lot of cells over here.

01:04.770 --> 01:05.010
Okay.

01:05.040 --> 01:06.180
So let's start.

01:06.180 --> 01:10.740
So first of all, uh, the first thing that we are going to discuss is how to create a set.

01:10.770 --> 01:11.310
Okay.

01:11.430 --> 01:18.000
And creating a set is specifically using curly braces like how we actually did in the dictionary.

01:18.000 --> 01:23.040
But only one difference that is present between sets and dictionary is that in dictionary we usually

01:23.040 --> 01:24.060
give key value pairs.

01:24.090 --> 01:24.450
Right.

01:24.450 --> 01:28.470
So let's say if I am going to define my underscore set over here okay.

01:28.470 --> 01:30.660
So I will just go ahead and use curly braces.

01:30.660 --> 01:33.420
And I'll just go ahead and write 12345 elements okay.

01:33.420 --> 01:42.660
And if I go ahead and print my set over here and also see the type of print type of my set, then here

01:42.660 --> 01:48.150
you will be able to see that, hey, I am able to get it over here, something like this.

01:48.180 --> 01:48.510
See.

01:48.510 --> 01:51.150
So all the elements is basically getting displayed.

01:51.150 --> 01:54.270
And over here you can actually see that it is a class set.

01:54.300 --> 01:54.810
Okay.

01:54.840 --> 01:58.080
Now if I also want to go ahead and create my empty set.

01:58.080 --> 02:01.420
So here I can go ahead and write my empty underscore set.

02:01.450 --> 02:02.200
Okay.

02:02.740 --> 02:04.360
I can directly use the class.

02:04.390 --> 02:04.750
Okay.

02:04.780 --> 02:05.710
Something like this.

02:05.710 --> 02:11.020
So if I go ahead and create like this, then I'm going to get my empty set itself right.

02:11.020 --> 02:12.850
So I'll just go ahead and print it.

02:12.850 --> 02:15.850
So here you can see the type is nothing but it is a class set.

02:15.850 --> 02:20.770
But since I have not put up any elements so over here you'll be able to see that it will be a empty

02:20.800 --> 02:21.220
set.

02:21.250 --> 02:24.130
Now along with this, what I will do, I will just go ahead and copy this.

02:24.130 --> 02:27.460
And let's say that inside this set I can give tuples, I can give list.

02:27.460 --> 02:33.220
And also if I go ahead and give 123456I will probably execute this also.

02:33.400 --> 02:33.820
Okay.

02:33.850 --> 02:37.930
So let's go ahead and print this right now over here okay.

02:37.960 --> 02:39.280
And let's see the sets.

02:39.310 --> 02:39.730
Right.

02:39.730 --> 02:43.990
So this is one of the most uh uh way like easy way.

02:44.020 --> 02:47.800
Probably take a list or a tuple and just type cast with the help of set class.

02:47.830 --> 02:48.070
Right.

02:48.070 --> 02:50.710
And here you'll be able to see that I will be able to get the set.

02:50.740 --> 02:53.410
Now, one of the functionality that I have actually told you over here.

02:53.440 --> 02:53.920
Right.

02:54.130 --> 03:00.100
Uh, Python sets are nothing, but it is built in data type used to store collection of unique items.

03:00.100 --> 03:02.470
Okay, so what does this basically mean?

03:02.500 --> 03:05.680
So if I go ahead and copy this and execute it.

03:05.680 --> 03:11.560
So let's say this is my set itself I will not say my empty set because now we have elements okay.

03:11.560 --> 03:13.870
And here also I will just go ahead and remove this.

03:14.260 --> 03:16.360
So let's say that this is my set right.

03:16.390 --> 03:19.240
Now let me just go ahead and write some duplicate elements.

03:19.270 --> 03:23.530
Let's say over here I'll go ahead and write six comma five comma 456.

03:23.530 --> 03:23.860
Right.

03:23.890 --> 03:28.300
Now even though I have duplicate elements, what it is going to do is that it is just going to ignore

03:28.330 --> 03:30.880
the duplicate elements and take only one element of the similar type.

03:30.910 --> 03:31.270
Right.

03:31.300 --> 03:33.670
So here you can say six and five are duplicate elements.

03:33.670 --> 03:36.700
So what it will do it will just display one time five and six.

03:36.700 --> 03:40.750
So if I go ahead and execute it here you can see that I'm getting 123456.

03:40.780 --> 03:41.170
Right.

03:41.200 --> 03:46.960
And as said over here you can see they are unordered meaning that the elements do not follow a specific

03:46.960 --> 03:49.810
order and they do not allow duplicate elements.

03:49.840 --> 03:50.200
Okay.

03:50.230 --> 03:52.210
Sets are useful for membership test and all.

03:52.210 --> 03:53.530
We will have a look onto that.

03:53.560 --> 03:53.950
Okay.

03:53.950 --> 03:59.530
So uh, now let's go ahead with some of the basic set operations okay.

03:59.560 --> 04:02.170
Basic set Operations.

04:02.200 --> 04:02.680
Okay.

04:02.710 --> 04:07.630
Now, with respect to basic set operation, the first thing that I am going to show you is adding and

04:07.720 --> 04:09.700
removing elements.

04:09.730 --> 04:10.240
Okay.

04:10.300 --> 04:13.690
Adding and removing elements.

04:13.720 --> 04:19.150
Now in order to add and remove the elements, I can probably let's say this is my underscore set over

04:19.150 --> 04:19.510
here.

04:19.540 --> 04:21.550
Let's say I want to add more elements over here.

04:21.580 --> 04:21.850
Right.

04:21.850 --> 04:23.290
And then I will try to print it.

04:23.320 --> 04:26.740
So for that what I have to do is that go ahead and use my add method.

04:26.740 --> 04:31.240
And let's say here I want to add a specific, uh, you know, element over here.

04:31.240 --> 04:31.840
Let's say seven.

04:31.840 --> 04:32.950
I want to go ahead and add it.

04:32.950 --> 04:37.300
And I will just go ahead and print my underscore set okay.

04:37.330 --> 04:41.110
So if I go ahead and execute it here you'll be able to see 123456 okay.

04:41.140 --> 04:46.240
Similarly if I go ahead and add the same element okay then you know what it will happen.

04:46.840 --> 04:52.570
Then it is just going to ignore the repeated elements, because I have already, uh, added that in

04:52.570 --> 04:52.930
the set.

04:52.960 --> 04:57.310
So here also you'll be able to see that I'm going to get 123456 okay.

04:57.340 --> 04:59.170
Now coming to the removing the elements.

04:59.170 --> 05:02.000
So in order to remove the elements from a set.

05:02.300 --> 05:02.810
Okay.

05:03.140 --> 05:04.670
From a set.

05:04.700 --> 05:09.680
So what I'm actually going to do I'll just go ahead and write my underscore set dot remove.

05:09.710 --> 05:10.190
Okay.

05:10.400 --> 05:12.620
My underscore set dot remove.

05:12.620 --> 05:15.920
And here I'm going to specifically use one element let's say three.

05:15.920 --> 05:20.300
And I'll just go ahead and print my underscore set.

05:20.420 --> 05:24.470
And now here you can see that the third element is already not present.

05:24.500 --> 05:25.010
Okay.

05:25.400 --> 05:32.000
Uh let's say uh uh, what happens if I try to remove an element which is not present at all?

05:32.030 --> 05:37.490
Okay, so for that, uh, let's say I'll go ahead and write my underscore set dot remove.

05:37.670 --> 05:38.270
Okay.

05:38.300 --> 05:40.880
Remove of element ten.

05:40.910 --> 05:41.360
Okay.

05:41.390 --> 05:46.160
So if I go ahead and execute it, it shows that hey there is a key error because I don't have that specific

05:46.160 --> 05:46.460
element.

05:46.490 --> 05:47.000
Okay.

05:47.360 --> 05:53.750
Uh, now there may be scenario that I need to have a scenario that if an element is not present in the

05:53.750 --> 05:55.310
set, it should not give us an error.

05:55.340 --> 05:55.670
Okay.

05:55.700 --> 05:56.720
It should just continue.

05:56.720 --> 05:57.890
If there is an element it should remove.

05:57.920 --> 05:59.330
Otherwise it should not give us an error.

05:59.330 --> 06:03.190
So for that what I will do I will just go ahead and run my underscore set dot discard.

06:03.190 --> 06:07.870
And let's say inside this I'm going to remove an element called as 10 or 11 whatever.

06:07.900 --> 06:12.010
If I go ahead and execute it here, you'll be able to see that I'm not getting any error right.

06:12.010 --> 06:13.720
Even though I go ahead and print it.

06:13.750 --> 06:14.050
Right.

06:14.080 --> 06:16.780
So print my underscore set over here.

06:16.780 --> 06:18.760
And here you can see 1234567.

06:18.760 --> 06:23.680
So that basically means if I'm using this discard method right it will just go ahead and see remove

06:23.680 --> 06:25.390
an element from a set if it is a member.

06:25.420 --> 06:25.690
Right.

06:25.720 --> 06:28.270
If that particular element is there it will it will remove.

06:28.300 --> 06:31.210
Otherwise it will just make sure that it will not give us an error.

06:31.240 --> 06:31.750
Okay.

06:32.050 --> 06:36.010
Now removing a random element right using pop.

06:36.010 --> 06:38.380
So here we also have something called as pop method.

06:38.380 --> 06:41.110
Let's see what is exactly this pop method right.

06:41.110 --> 06:44.020
So for pop method I will just go ahead and write.

06:44.020 --> 06:47.170
This is my removed element okay.

06:47.200 --> 06:52.660
And then I will just go ahead and write my underscore set dot remove.

06:52.690 --> 06:58.150
Oh sorry dot pop my underscore set dot pop okay.

06:58.180 --> 07:02.910
And what I'm actually going to do I'm just go ahead and display my print removed element.

07:02.940 --> 07:07.140
First of all, print remove element.

07:07.140 --> 07:10.620
And then I'm also going to print my my underscore set.

07:10.980 --> 07:11.520
Okay.

07:11.580 --> 07:15.090
So here if I probably go ahead and display it right.

07:15.090 --> 07:19.980
So over here you can see with respect to set it is just like first in first out right.

07:19.980 --> 07:24.660
So whatever element is first uh inserted that element only will get removed.

07:24.660 --> 07:27.900
So that is the reason why I'm getting is something like 24567.

07:27.930 --> 07:28.350
Okay.

07:28.380 --> 07:34.170
So, uh, here you can see that whenever I have an element, I should be able to remove it just by using

07:34.170 --> 07:34.440
pop.

07:34.440 --> 07:36.540
And I will also be able to get the element itself.

07:36.570 --> 07:37.080
Okay.

07:37.140 --> 07:43.560
And finally, if you really want to clear all the elements, okay, all the elements, you can just

07:43.560 --> 07:47.220
go ahead and write my underscore set dot clear perfect.

07:47.220 --> 07:51.360
And here you can go ahead and just print the set okay.

07:51.360 --> 07:54.960
So this will basically be my print my underscore set.

07:54.990 --> 07:55.650
Perfect.

07:55.650 --> 08:02.370
So if you see this and if I execute it here you can see that I'm actually getting a empty set altogether.

08:02.400 --> 08:04.950
Okay, now let's go ahead and see some more examples.

08:04.980 --> 08:08.520
So first of all I'm going to show you set membership test.

08:09.150 --> 08:09.480
Okay.

08:09.510 --> 08:10.830
Membership.

08:11.580 --> 08:14.310
Membership test.

08:14.340 --> 08:14.850
Okay.

08:14.880 --> 08:20.070
Now with respect to membership test, it's just like whether an element is present in the test or not,

08:20.100 --> 08:23.130
whether an element is a member of a set or not.

08:23.130 --> 08:24.540
That is what we will basically check.

08:24.540 --> 08:28.320
So I'm going to write for my underscore set is nothing but 12345.

08:28.320 --> 08:32.190
And here I will just go ahead and write print let's say.

08:32.580 --> 08:34.500
And here we'll use an in operation.

08:34.530 --> 08:34.740
Right.

08:34.770 --> 08:40.500
Let's say I'll take an element three in R three in my underscore set right.

08:40.530 --> 08:46.440
So here if I go ahead and print it or if I go ahead and print ten in my underscore set.

08:46.470 --> 08:46.920
Right.

08:46.920 --> 08:50.520
So if the element is basically present in set it is just going to give us true.

08:50.550 --> 08:51.930
Otherwise it is going to give us false.

08:51.930 --> 08:52.770
So that is the reason here.

08:52.770 --> 08:58.380
You can see when I'm checking whether ten is present in my set or not, I'm actually getting false.

08:58.380 --> 09:00.600
But when I'm checking three is in my set or not.

09:00.600 --> 09:02.190
So here I'm actually getting true.

09:02.210 --> 09:02.570
right?

09:02.600 --> 09:07.220
So that is the reason is just checking whether this particular element belongs to that particular member

09:07.250 --> 09:07.700
or not.

09:07.730 --> 09:11.000
Now let's go ahead and see some more mathematical operation.

09:11.030 --> 09:14.210
Mathematical operations.

09:14.240 --> 09:14.600
Okay.

09:14.630 --> 09:17.780
Now in this particular case, let's say I go ahead and create my set one.

09:17.810 --> 09:20.120
Let's say it will be one, two, three, four, four.

09:20.150 --> 09:21.710
Okay I'll have four elements.

09:21.740 --> 09:21.950
Okay.

09:21.950 --> 09:26.990
Just to give you an idea over here and or let me just go ahead and write something like this.

09:27.050 --> 09:28.550
Four comma five comma six.

09:28.550 --> 09:31.070
Let me just add more element and this will be a set two.

09:31.100 --> 09:31.520
Okay.

09:31.550 --> 09:38.600
Now inside this set two let me just go ahead and write uh from four let's say four comma 56789.

09:38.630 --> 09:38.960
Okay.

09:38.990 --> 09:41.540
So these are my uh, basically all the elements.

09:41.540 --> 09:44.930
So first operation that we are basically going to discuss is nothing but union.

09:44.930 --> 09:48.410
Union basically means when I have two sets I'll just combine all the elements.

09:48.440 --> 09:48.740
Right.

09:48.770 --> 09:51.470
So in order to get the entire union set.

09:51.470 --> 09:57.740
So here in set also you will be able to see that I will be having lot of inbuilt methods.

09:57.770 --> 09:57.980
Okay.

09:58.010 --> 10:00.380
So there is something like difference difference update.

10:00.530 --> 10:02.240
Um and uh is lower.

10:02.270 --> 10:03.440
Is this this is there.

10:03.440 --> 10:04.820
And let's say symmetric difference.

10:04.850 --> 10:05.900
Is there symmetric difference.

10:05.900 --> 10:06.290
Update.

10:06.290 --> 10:07.280
Is there, union is there.

10:07.280 --> 10:07.850
So I'm just going.

10:07.880 --> 10:10.520
To write say uh set one dot union.

10:10.520 --> 10:14.060
And here I'm going to specifically use set two right.

10:14.090 --> 10:20.420
Now if I go ahead and print my union underscore set you will be able to see that I will be.

10:20.450 --> 10:22.130
Able to get the output.

10:22.130 --> 10:24.800
So I'm getting an error because of uh syntax.

10:24.800 --> 10:26.990
So here you can see all the elements has been combined.

10:26.990 --> 10:29.390
Union basically means you're combining everything okay.

10:29.420 --> 10:31.700
So 123456789 okay.

10:31.730 --> 10:35.540
So this is one of the operation most common operation that we do in sets.

10:35.540 --> 10:38.960
The next operation that we are basically going to do is something called as intersection.

10:38.990 --> 10:40.940
Now intersection is nothing.

10:40.940 --> 10:46.070
But it will basically give us a common set of common elements from both the sets.

10:46.100 --> 10:46.400
Right.

10:46.400 --> 10:49.160
So here I'm going to probably create the intersection underscore set.

10:49.190 --> 10:50.690
Let's say I'll just go ahead and write.

10:50.930 --> 10:57.200
Uh so here you can see set one dot intersection of whatever.

10:57.230 --> 10:58.100
Why will not be there.

10:58.100 --> 11:01.700
Here I will just go ahead and write set two okay.

11:02.090 --> 11:03.530
Set two.

11:03.560 --> 11:04.160
Okay.

11:06.410 --> 11:06.650
Okay.

11:06.680 --> 11:07.310
Set two.

11:07.340 --> 11:07.670
Okay.

11:07.700 --> 11:10.970
Now, if I go ahead and print my intersection set.

11:11.090 --> 11:14.780
So here let's go ahead and see this intersection set.

11:14.810 --> 11:16.910
Here you'll be able to see only the common elements.

11:16.910 --> 11:17.660
It will be able to give.

11:17.690 --> 11:20.720
So 456 are common available in both the sets.

11:20.720 --> 11:23.690
So that is the reason it is basically getting displayed.

11:23.900 --> 11:25.910
Uh let's see one more operation.

11:25.910 --> 11:27.530
I don't know whether it is present or not.

11:27.530 --> 11:29.120
It is called as union okay.

11:29.150 --> 11:30.620
So only union is present over there.

11:30.620 --> 11:31.340
No worries.

11:31.550 --> 11:33.740
Okay, let's do one more thing.

11:34.610 --> 11:37.730
Let me just go ahead and write something like this.

11:37.880 --> 11:39.770
Or set one okay.

11:39.800 --> 11:41.630
Set one dot.

11:41.930 --> 11:45.470
Uh intersection update okay.

11:45.500 --> 11:47.030
So we will try to see this okay.

11:47.060 --> 11:50.210
What is this function called as intersection update okay.

11:50.240 --> 11:53.120
And here I'm basically going to give set two okay.

11:53.720 --> 11:57.830
Uh so here the kind of operations that we are actually doing.

11:57.830 --> 12:01.490
And if I go ahead and print my set one okay.

12:01.520 --> 12:03.470
If I'm going ahead and printing my set.

12:03.500 --> 12:04.670
One, please focus on this.

12:04.700 --> 12:06.410
Okay, let's see this.

12:06.440 --> 12:07.730
What will be the third print?

12:07.760 --> 12:08.000
Right.

12:08.030 --> 12:08.450
First print.

12:08.480 --> 12:09.530
You know it will be the union.

12:09.560 --> 12:11.420
Second print will be the intersection.

12:11.420 --> 12:16.010
And third print whenever we use intersection underscore update offset two.

12:16.040 --> 12:18.680
Now if I just go ahead and print it here, you will be able to see.

12:18.710 --> 12:22.040
Now when we did this intersection underscore update.

12:22.040 --> 12:24.200
So whatever are the common elements from set one.

12:24.200 --> 12:25.700
And set two that we got it.

12:25.700 --> 12:28.820
And that all elements got updated in set one.

12:28.820 --> 12:31.760
That is most important that you really need to understand over here.

12:31.760 --> 12:37.280
Intersection underscore update basically means whatever operation specifically intersection we are doing

12:37.280 --> 12:41.600
over here, it will just find out the common elements and it will update in the set one.

12:41.600 --> 12:46.790
So that is the reason I'm actually able to get 456 when I'm printing set one okay.

12:46.820 --> 12:49.460
So please make sure that you keep this in mind.

12:49.460 --> 12:54.620
And whenever we do intersection or difference there will also be a difference underscore update intersection

12:54.650 --> 12:55.910
underscore update altogether.

12:55.940 --> 12:56.330
Right.

12:56.330 --> 13:00.110
So this is what I have actually showed you one example okay.

13:00.140 --> 13:05.180
So please make sure that any operation underscore and update basically means will perform that operation

13:05.210 --> 13:07.610
and will update in one of the set itself.

13:07.640 --> 13:08.000
Right.

13:08.000 --> 13:11.330
So I will go ahead and create my another set one and set two.

13:11.360 --> 13:14.180
Now this time let me go ahead and create difference right.

13:14.210 --> 13:15.020
Difference operation.

13:15.020 --> 13:15.770
Let's discuss.

13:15.770 --> 13:23.330
So if I go ahead and write set one dot difference of again I don't know why this is giving us x and

13:23.330 --> 13:23.750
y.

13:23.780 --> 13:25.670
I think by default it is taking us.

13:25.670 --> 13:28.970
And then we go ahead and write set one dot difference of set two.

13:29.390 --> 13:34.820
Now if I go ahead and print it print the element of this.

13:35.990 --> 13:36.410
Okay.

13:36.410 --> 13:40.100
So here you'll be able to see set one minus difference of set two.

13:40.130 --> 13:42.380
Set one dot difference of set two.

13:42.410 --> 13:47.510
That basically means from set one we will remove the common elements that are present in set two.

13:47.540 --> 13:49.910
So here you can see 456 has been removed.

13:49.910 --> 13:53.180
And here I am actually able to get the output as 123.

13:53.210 --> 13:53.660
Okay.

13:53.690 --> 13:54.950
There is also one method.

13:54.950 --> 13:58.880
As I said difference underscore update difference underscore update basically means it will perform

13:58.880 --> 14:01.550
that operation difference and it will update in the set one.

14:01.550 --> 14:03.050
So in set one I will be able to see.

14:03.070 --> 14:07.090
Right now it is, uh, if I probably see right now it is set.

14:07.120 --> 14:10.150
One is nothing, but it is having all these elements one, two, three, four, five, six.

14:10.150 --> 14:13.210
But when I do difference underscore update, there is a method over here.

14:13.240 --> 14:19.000
It is going to make sure that it updates this difference operation whatever output is coming in.

14:19.000 --> 14:19.900
Set one okay.

14:19.930 --> 14:21.550
This is the basic difference.

14:21.790 --> 14:27.970
Um now let's do one more thing and again see if I want to remove all the common elements from set two.

14:28.000 --> 14:29.800
I can also go ahead and write something like this.

14:29.800 --> 14:32.020
Set two dot difference.

14:32.380 --> 14:37.150
Uh set two dot difference over here and here I will just go ahead and write my set one.

14:37.150 --> 14:43.330
So whatever is my element that is available in whatever is my unique elements or remaining elements

14:43.330 --> 14:48.310
in set two and set one elements has been removed because four, five, six is the common element over

14:48.310 --> 14:48.700
here.

14:48.730 --> 14:48.970
Right?

14:48.970 --> 14:51.160
And that is the reason I'm actually getting it over here.

14:51.340 --> 14:51.850
Right.

14:51.850 --> 14:58.120
So, uh, I hope you are able to understand till here and all uh, uh, one more operation that we are

14:58.120 --> 15:01.780
going to discuss is nothing but symmetric difference.

15:01.780 --> 15:02.200
Okay.

15:02.200 --> 15:05.710
And let's see whether you will be able to understand what exactly this is.

15:05.710 --> 15:12.040
So if I go ahead and write set one dot symmetric difference okay of set two okay.

15:12.040 --> 15:12.730
Let's see.

15:13.540 --> 15:18.430
Now if I go ahead and execute it here I am able to get 123789.

15:18.430 --> 15:23.170
That basically means both the both the unique elements from both the sets are combined.

15:23.200 --> 15:24.880
Common elements are just removed.

15:24.910 --> 15:25.420
Okay.

15:25.480 --> 15:29.050
So these were some of the mathematical operations that we probably perform.

15:29.080 --> 15:29.920
Again I will repeat it.

15:29.920 --> 15:34.270
Symmetrical difference is nothing but from set one and set two which are the common elements only that

15:34.270 --> 15:38.140
will be removed and remaining all the unique elements from both the set will be combined.

15:38.170 --> 15:42.820
Okay, so that basically the intersection elements is just removed over there.

15:42.850 --> 15:43.090
Okay.

15:43.120 --> 15:45.550
So that is what symmetric difference basically means.

15:45.550 --> 15:47.380
And you can also do the vice versa.

15:47.410 --> 15:50.230
Set two dot symmetric underscore difference of set one.

15:50.230 --> 15:53.380
You'll be able to get the same answer okay.

15:53.410 --> 15:54.640
Now let's do one thing.

15:54.670 --> 16:00.580
Let me make go ahead and make some more cell okay I'll go ahead and make some more cell.

16:00.580 --> 16:04.770
And let's discuss about some of the sets methods.

16:04.800 --> 16:05.340
Okay.

16:05.700 --> 16:07.020
Again important one.

16:07.020 --> 16:09.300
You may be using some or the other thing over here.

16:09.330 --> 16:09.840
Right.

16:09.840 --> 16:13.560
So first of all I will just go ahead and create my set one.

16:13.860 --> 16:16.170
And let's say I'm going to write 123 okay.

16:16.200 --> 16:21.240
Three elements are there in set two I'm just going to write three comma four comma five.

16:21.270 --> 16:26.820
Right now first of all we will go ahead and see what is subset okay.

16:26.850 --> 16:27.750
Is subset.

16:27.780 --> 16:34.560
Now with respect to its subset I will just go ahead and print set one dot is subset okay.

16:34.590 --> 16:39.690
Set one dot is subset of set two okay.

16:39.780 --> 16:45.000
Now once I do this you will be able to see we are just checking whether set one is a subset of set two

16:45.000 --> 16:49.140
or not is subset basically means all the elements that is present in set one.

16:49.140 --> 16:50.790
Is it also available in set two?

16:50.820 --> 16:53.490
Is this the parent uh, parent?

16:53.550 --> 16:58.770
I can I can just say is it the parent uh, set which has the all the elements of set one.

16:58.770 --> 17:00.870
So right now here you can see that I do not have it.

17:00.870 --> 17:01.230
Right.

17:01.230 --> 17:02.850
Because set one is not available.

17:02.850 --> 17:05.380
One of the element is also not available is set to right.

17:05.410 --> 17:08.320
So if I just go ahead and execute it here you can see it is false.

17:08.350 --> 17:08.860
Okay.

17:09.160 --> 17:14.080
Uh, the next one is just to check whether set one is the superset of set two okay.

17:14.110 --> 17:23.680
So if I go ahead and write set one is is superset is superset of set two.

17:26.350 --> 17:28.540
Is set a superset of set two.

17:28.570 --> 17:30.100
I'll just go ahead and print it.

17:30.100 --> 17:33.970
And here you will be able to see that I will be able to get the answer.

17:33.970 --> 17:35.740
So here right now it is false.

17:35.770 --> 17:41.620
Again set one is not a superset of set uh set two it checks if set one is a superset.

17:41.650 --> 17:44.980
Superset basically whether it has all the elements of set two or not okay.

17:45.010 --> 17:49.900
So this is also false because it does not let's say if I go ahead and write like this 345.

17:49.930 --> 17:55.060
Now if I execute it here you can see set one is not subset of set two because here there are more elements.

17:55.060 --> 17:57.220
But if I go ahead and write set one is superset of set two.

17:57.220 --> 17:59.320
Because this 345 is also available over here.

17:59.350 --> 18:00.610
You can actually see.

18:00.640 --> 18:01.000
Right.

18:01.030 --> 18:04.330
If I just remove five also, then also you'll be able to see both are false, right?

18:04.360 --> 18:06.940
It should at least have all the elements from either one of the set.

18:06.970 --> 18:13.030
Okay, so this is what is an example with respect to some of the methods that we use is set.

18:13.060 --> 18:14.320
It is superset.

18:14.320 --> 18:18.340
And again guys there are a lot of methods that are available in sets which you should definitely keep

18:18.340 --> 18:19.870
on practicing and keep on seeing.

18:19.900 --> 18:20.380
Okay.

18:20.470 --> 18:24.310
Now uh, let's let's do one kind of task.

18:24.340 --> 18:24.580
Okay.

18:24.610 --> 18:27.580
So here, uh, let's say I have some numbers.

18:27.610 --> 18:27.970
Okay.

18:28.000 --> 18:29.650
I or I have a list.

18:29.830 --> 18:30.190
Okay.

18:30.220 --> 18:30.850
List.

18:30.850 --> 18:33.430
And with respect to this list, I will just go ahead and run.

18:33.430 --> 18:34.480
One, two, two.

18:34.630 --> 18:38.170
Um, let's say three four comma four comma five.

18:38.200 --> 18:38.410
Okay.

18:38.440 --> 18:39.370
So these are my elements.

18:39.400 --> 18:39.910
Okay.

18:39.910 --> 18:45.460
Now if I just want to quickly remove the duplicates from this list okay.

18:45.490 --> 18:49.180
From this list what I can do, I just have to convert this into a set.

18:49.180 --> 18:54.370
So if I go ahead and write set of list here, you'll be able to see hey, I am going to get all my unique

18:54.370 --> 18:55.570
elements 1234, five.

18:55.600 --> 18:55.870
Right.

18:55.870 --> 18:57.070
So simple it is.

18:57.100 --> 19:01.720
If question is basically asked whether you really need to find out a list of elements, you can basically

19:01.720 --> 19:02.560
do that okay.

19:02.680 --> 19:06.720
Now, Now let's do one practical example here.

19:06.840 --> 19:15.450
What I'm actually going to do is that I'll just go ahead and write counting unique words in text.

19:16.230 --> 19:18.810
Let's say if I have a sentence text.

19:21.870 --> 19:28.770
In this tutorial we are discussing about sets.

19:28.800 --> 19:29.370
Okay.

19:29.850 --> 19:30.780
So here it is.

19:30.780 --> 19:35.190
So I will just go ahead and uh, I need to basically count unique words in text.

19:35.220 --> 19:36.990
How many unique words are basically there.

19:36.990 --> 19:39.750
And then we can basically do that very much simple.

19:39.750 --> 19:43.140
So here first of all what I will do I will just go ahead and create a variable words.

19:43.140 --> 19:46.500
I will take this text and I will do the entire split okay.

19:46.530 --> 19:49.440
I will get all the elements over here with respect to the split.

19:49.440 --> 19:58.320
And then you will be able to see convert list of words to set okay.

19:59.460 --> 20:04.400
To get unique words Okay.

20:04.670 --> 20:07.130
Unique underscore words.

20:08.990 --> 20:09.350
Okay.

20:09.380 --> 20:10.400
Unique underscore words.

20:10.400 --> 20:11.030
How do we get it.

20:11.060 --> 20:14.120
We just need to use set of all these words.

20:14.150 --> 20:14.450
Okay.

20:14.480 --> 20:16.700
Whatever words we are specifically given.

20:16.880 --> 20:17.360
Okay.

20:17.660 --> 20:21.080
So once I get the unique words I will just go ahead and print it.

20:21.110 --> 20:24.020
Print all unique words.

20:24.020 --> 20:27.500
And then after that I'm also going to print the length of the unique words.

20:27.530 --> 20:29.420
Length function is there.

20:29.420 --> 20:34.400
And let me just go ahead and write length of unique words.

20:34.430 --> 20:34.940
Okay.

20:34.970 --> 20:35.990
If I go ahead and execute.

20:35.990 --> 20:39.380
So tutorial we are discussing this in about sets R right.

20:39.380 --> 20:41.540
So eight unique words are specifically there.

20:41.540 --> 20:44.360
And here you can actually see that how I actually printed it right.

20:44.390 --> 20:45.170
Simple.

20:45.290 --> 20:48.200
So I hope you liked this particular video.

20:48.200 --> 20:52.610
With respect to sets we have almost discussed each and everything like common key methods, errors,

20:52.610 --> 20:58.430
what kind of errors you feel and what are the common, you know, functionalities methods with respect

20:58.430 --> 20:59.090
to the sets.

20:59.090 --> 21:02.720
So I hope you were able to understand this particular session.

21:02.720 --> 21:04.130
I will see you all in the next video.

21:04.130 --> 21:04.550
Thank you.

21:04.580 --> 21:04.970
Take care.
