0:00
Hello everyone we will be talking about next chapter that is SIDS so I'll explain what are these set that
0:05
data type and how they are different from seeing list tuples that we already discussed right now to represent a group of unique values at the single entity we use states so basically we have seen in list we are defining them with the square racket doubles we are defining them with a round bracket strings were defined with the single quotes
0:29
and now whenever we areский it is defined with curle braces okay so here
0:36
one of unique point in sets is that there are no duplicates items
0:42
allowed inside sets for example in tuple we have seen we can use duplicate element
0:47
in double as well right but in sets we only should have identical elements
0:53
not a duplicate one insertion order is also not preserved that means in list your first
0:59
was called with its index of zero similar was the case with double but inside
1:05
sets you have to call it with the key of that element so basically indexing and
1:13
slicing that's why is not allowed in sets right so basically whenever I am
1:17
say set of one that means I am calling with the element name rather than its
1:23
index okay so that is a highlighted difference between list double and sets
1:28
Now, set are notable. So that means you can just go and assign different values to set and from outside and that
1:36
value we get updated. We can represent a set element with curly races and comma separation that we have seen this curly races and these are common separated values There are different mathematical operations that we can perform in different sets For
1:51
example we have these two sets and now we have to perform union intersection differences
1:58
etc we can perform then that we will see in next slide
2:02
Basically how to create set there are different ways just like how we have seen
2:07
list can be created with this empty. Tuffle can be be created or even MTV so similar way whenever you wanted to create a set you
2:17
can just do curly braces values comma separated that is set or otherwise whatever the list is
2:23
there you can just typecast it seeing set of l and that one will be converted to
2:31
set's right whatever the list that you are talking about it will be converted also you can use the
2:36
range function we have seen range function will do five means zero to four
2:40
to 4 all these elements will be considered and then set means it will convert it to
2:47
opening and curly braces so that's why 0 1 2 3 4 will be printed as a set so there is a one
2:53
important point to note here is that to create empty set we have to take a special care
2:59
while if at all you are just seeing just like a list just like tuple i am just creating this
3:05
way and seeing it is as a set it will be raw right it is additional
3:10
instead of seat. So that's why whenever you want it to quilt empty set, you always have to do this way
3:16
That is set of empty values. So this is a special note in seats
3:22
Then there are different operations like union That means we are just adding these two seats and checking what is the final output Then we have intersection that means what are the common elements in those what are the differences what is symmetric differences so all of these different operations that we have seen
3:43
in operators as well so basically when i am talking about union that means we are talking about
3:49
r intersection means and differences means subtraction and then we have xr operations we
3:56
with symmetrical differences. All of these outputs are printed over here. So now we'll see
4:02
all these examples in Jupiter output. And similar way, these are the definition that I was talking
4:09
about to define the set. I'm just running them with the shift enter. Then we have functions
4:16
like different functions are there in set as well. For example, we are defined one set as with
4:23
the values of 10, 20 and 30. I wanted to do that. add a value singular way inside our list we used to do append or insert with the indexes
4:32
so here you can just directly use dot add method to add this element to the set now to update
4:38
you can just use this L in the range of 5 and then print S C so output will be just let me
4:47
do shift enter work here and I will just minimize a bit so that we will have all those
4:56
output okay so here whenever you're adding this 40 is added at the first right because we do
5:03
not have indexing and slicing in the seats that is a key important point it is not going to get
5:08
added at last it is going to add it at first now we have this we are just updating with the band of five so all this will be added to first and then we will have remaining values as it is from our list Anywhere I am doing the copy we can just see all the element
5:26
will be copied and one more set will be created similar to the original one. Now whenever
5:32
I am talking about pop method in the list it was removed, it was removing only the last element
5:38
right but inside of seat it will just remove a return random element from the seat
5:43
because we do not follow indexing. So that's why whenever you are doing L. Dot BUP
5:48
so it will pop out the random element. So it has popped out first element over here
5:53
Now whenever you are talking about Biscart method, for this 10 element, it will check if this element is there
5:59
inside the set, if then only it will remove it. If it is not there, then we won't get any error
6:08
But whenever we are saying else dot clear, it will just remove all the elements from the set
6:13
and print empty set. Right? See this is a definition of empty set
6:17
Here to be noted that there are no opening and closing empty values
6:39
that will be considered as additionality. Now whenever instead of the discard if you are using remove method, it will check if that value is there inside that set. If not it will give an error seeing the value is not there available in your set. So that is a different between remove and discard
6:40
This will be one of your good interview question. Then there are different operations that we have seen, that is union intersection differences and symmetrical differences
6:49
So I will just run those and we can see all additional subtraction and then XR operations are being performed on these two seats
6:58
So that is it about the seats. We will see in next chapter with the dictionaries