Python sits, so that is another data available in PyCon.
In Python is it is an unordered collection of unique items, no duplicate elements are allowed in,
set and must be immutable that bones which cannot be changed.
So however, the set itself is mutable, we can add or remove items from it.
So now we have defined what is a set.
And in Python we usually include the set within Kali Brezhnev's as set.
Members must be unordered and they'll be each and every little item will be unique in values.
So this can be used to perform the mathematical set operations like your union intersection, semantic
difference and so on.
So here we are discussing what is said union, so let us suppose a Z visa visit and if you do the union,
that is a union B, so these are the elements were selecting deputies were selecting all the elements
either belonging to A or B or both.
We are going for to set intersection.
So if you take the intersection between the set and B, then all those elements will be belonging which
are common between A and B sets.
Here you is actually standing for the universal set.
Next one is a set of operations continue.
That is the difference if you do A minus B, if you do A minus B, then you are remaining with those
elements, which will be in A, not in B, but if you do the set set symmetric difference.
In that case, if you go for a set symmetric difference B, then those elements will be will be selected,
which could be either in A or in B, not in common.
So here we are having the Biton set methods, so Ed, so he can add an element to our set clear, remove
all elements from a set copy returns the A copy of a set next.
What is the difference?
Return the difference of two or more sets as a new set.
They're going for the difference a bit.
Discard remove an element from the set.
If it is a member, do nothing.
The element is not belonging to the set, not a member of the set intersection intersection a bit is
disjoined return true if two sets have a null intersection is subsect return true if another set contains
this particular set.
We're having this is superset.
We are having this pop that is the Bob method that is remove and return an arbitrary set element, it
is clear if the set is empty.
So in this scene, you see all the methods we have discussed with the respective shot discussions.
OK, next one is all return to if all elements of the set are true.
So these are the list of methods which are python building functions, which which are applicable with
set also.
So any return true if any element of the set is true, enumerate, return and enumerate object, it
contains the index and the value of all the items of the set as a appear so index.
That is a position number and the value so that can fall appear and that will be printed.
That would be the output here.
So now we are going for this line.
That is the return, the length.
That is a number of elements in the set.
So these are the other methods are there?
These are the python building functions which can be applied on the set.
So I think for the better clarity, let us go for one practical demonstration to show you that how these
methods can be applied on the set.
And before that, obviously, we should we should show you that what the what is a set, how to define
it and what are the different basic operations which you can carry out on?
Is it.
So here is the demonstration for you is it is an unordered collection of items that means within the
items, within the members of the set that is not ordering the elements.
The items can be in any order and every element must be unique, not duplicate.
Elements will be allowed in a set and must be imitable.
That means those elements cannot be updated, cannot be changed.
However, the set itself is mutable.
That means we can add or remove items from asset sales can be used for to perform the mathematical set
operations like our union intersection, semantic differenced, etc..
So let us discuss how to create one set here to define one set of integers in case upset.
The elements will be separated by commas and the whole set will be enclosed within calibrations.
So if I predict you can find that the set has been formed, a sip may have different type of data.
That means elements will be from mixed data types.
So here we are having this hundred and one of the type of integer organismal is the type of string.
And here we are having one tuple that can be also asset element.
So he can find that respective mindset, too, has got printed.
If we while defining one set, if I put some duplicate values, then those duplicate values will be
eliminated.
Only that unique values will be there in the set ultimately.
Now, in this case is it cannot have multiple items here, you can find that we are defining one set
or at least is as one of the elements, but list is containing multiple items.
So this particular set cannot be formed.
So if I are going printing.
If I try to form a different one, set it, then type it is coming, an honorable type list is their
respective error message.
So you can find that creation of a set from the list as one of the elements is not possible.
So we can make a set.
But we can make a set from a list using the method set.
So here we are having one list.
You are doing one method set here, and then we're going to get one set accordingly.
And now if I want to make one list from this set, the set will be enclosed within the calibrations.
And here we are using the method list and then we can get a list from this set here so we can find that
we have got one list here and here.
You can find the type of the my one.
So it had the class type list here.
Next, we're going for operations on a set so honest that we can perform multiple different operations.
So let me go one by one.
So at first, we are defining this particular set here, having the value 11, 30 to 44, 66 and 55,
you can see this set of values that there might be in the different order.
So now the set members cannot be accessed using index.
So zero is the index.
So if I want to access the mind, set one zero.
If I want to access this one, it will be coming.
And that type of the name of the edit is type error and set object does not support indexing is the
error message.
So that means I cannot do this one.
That means indexing is not allowed, not getting supported on a set.
OK, no next one is that so if we go for adding one single item so we can use that method and so in
that case, 77 will be added as one of the elements.
But if I want to add multiple items, then you can go for the method update.
And here the multiple items are to be enclosed within square because that means it is a list.
So list of items can be can be passed as input into the method that is our object.
In the case.
You can find that at 19 and 22, the three values have got added to the set.
Now you see, we can go for the update.
In the case of update, we can add at least we can add a set.
So here is the 100, 300, 400.
They are nothing but a set of 100 and 100 to nothing but a list.
So looking at the brackets and closed, we can easily find and then you can find that this particular
mindset one is having those values included and added.
Now we are going for remove and discard so you can find that in of remove and discard so initialised
mindset, so ETWAS mindset, one has got this set of values and we have printed that one.
Now we are going for discard for that discard an element which is not present.
But you can find that no edit is coming, no error messages coming because the discard will handle that
error in any situation.
So my let's set one.
If we go for my second printing then I'm getting the same set of items.
But if you use them instead of using the method discard, if you use that method remove and if you pass
of an element which is not there in the set, you'll be getting one error.
So I'm just going to show you that one.
So this is known as the name of it, so there is a name, my set is not defined here, so let me go
for this, my one, I think.
OK, so now if I go for this, I can find this one that is accurate so that B6 is not present in the
respective set because you can find that six is not present there, but 66 is present.
So 66 can be deleted, can be removed.
So in case something goes up.
So one very big difference between this discard and this remove is that in case of discard, if the
element, whatever we are passing as input argument is not present, it is not producing any error,
but in case of remove, it is producing an error on the name of the error.
Izquierda.
Now, if you go for to discard 44, if you want to print this myself, one in that case, I can find
that this 44 has been deleted.
If you go for this remove 55 and 55 is existing, the respective will get deleted from the set.
So now here we are going for the method that is a pop, and here we are having one set defined.
And now we are going for this mindset, one dark pop method, and then we can find that 33 has been
popped, popped out, has been deleted.
If you go for another time, pop method that 66 has been deleted here, this particular values can be
selected randomly.
So clear mind set.
In that case, the set will be existing.
My statement will be existing, but its all its elements will get cleared.
So I'm going to print my set one.
After issuing this clear method, we can find that at the city's existing, but no elements are there.
Let us go for a different set of operations, because we are going for this union, so we are having
mindset one, we are having mindset to bring those two sets.
Now, this union can be done using the idea, using the operator filter or using this method, not union.
So my set one dark union mindset, too.
So I have shown that in whatever the way in which we are doing the union ultimately leading to the same
result, that means union is taking place in union.
The duplicate values will be orcharding once.
So four and five, they are the duplicate values between these two sets.
My set one of say two, but they will be orcharding once because set will all is a collection of unordered
distinct elements.
So they'll be orcharding once, ultimately in the union after union.
What happened?
This intersection next one is our intersection.
You can find that mindset one and myself to at having the set of values there.
And if you go for the intersection then we're landing with this four and five only intersection can
be done using the operator ampersand, all using my set one dot intersection mindset to.
Next one, we are going for the set difference so it gets upset difference that you can use the operator
that is a minus, or you can use a method that is intersection.
So we can see that only the common elements will be coming out from the intersection.
So this is one of the very important operations on set.
So we are finding that four and five are the common elements in between the set mindset one and Mindset
two.
So they are coming up.
We are going for the set difference.
So here we are having this this mindset one on my set, too.
So the restrictive rules are there.
So now when we are going for this difference, then mindset one minus mindset to you will be landing
with this one.
One, two, three, four and five will be will be discarded because four and five, they are the common
in my set one and my set two.
But if you go for my set to minus my set, one will be getting this one.
There is that eight, nine, six, seven and four and five will not be there.
I next.
Well we can do the same either using operator minus or using the method different.
So it'll be getting the results accordingly.
Now we are going for the semantic difference in close up semantic difference, the common element in
case of semantic difference.
Common elements will not be coming.
So now we do for the semantic difference.
We'll be going for this Apakan it.
So this is a symbol Apakan it so also known as hat, so that you can go for this operator Arpad correct
or symmetric underscored difference.
So there is another method.
So here you can see that all the elements are out there, but only the common elements which are common.
There is a four and five between Mindset one and Mindset two.
They are not coming after doing the symmetric difference between my set one and my two.
Now we are going for this membership check.
So now here we are having one set is defined.
That is a mind set, one, two in my set, one that is quite obvious.
True, because two is one of the elements, one one of the members of this mindset, one.
So our coming to a through here.
So six in mind set one six is not there.
The outcome is false too.
Not in mind.
Set one.
So that is producing outcome false because two is there and six not in my set.
One, its outcome is true here.
Now we are going for this either iterating through a set so for later in set will come later.
So in this way you can find that for each and every iteration we are picking up one of the characters
from the string welcome.
And that is getting printed.
Now we are having some inbuilt functions with the set, so they are nothing but Lenn Max mentioned it
so denote the number of elements we can have six elements in mind set one.
So Leontes lane sprinting six eight, Maxus bending the maximum element.
Here it is, five minutes bending the minimum element of the set members.
It is sprinting zero at the shortest Misato will print set in the shortest form and outcome is of the
type of list.
But having this frozen set.
So Biton frozen set frozen set is a new class that has the characteristic of a set, but its elements
cannot be changed once assigned.
So while tables are immutable, lists and frozen sets are imitable sets here.
So we cannot do any kind of update and change on this frozen set.
So we know that tuples are the imitable lists and frozen assets are imitable sets here.
So here you have defined to frozen set.
That is a mindset, one on my set to define them and then we are going to print them so the values are
printed.
You can find that when I'm printing this mindset one, it is getting printed as the set and here we
are having the first brackets.
Then within that we're having this calibrations.
That is a set is there?
And then we're going for this difference so different.
My set one different mindset too.
We can get this one and two because one and two will be the elements which will be which will be there
as outcome three and four will be deleted because three and four are the common elements between this
Mindset one and mindset two.
We're going to go for the union.
We're getting this outcome like this.
We are going for the intersection.
Only the common elements are coming also to unfold.
We're going to go for the Semitic difference.
Only three and four will get discarded and race elements will be there in the frozen set.
But if I want to do some addition, if I do addition of a new element.
So in that case, in case of frozen set, it will produce error.
And this error is known as the attribute error proteins.
Set object has no attribute.
And so that's why this is the respective error we are facing, because a frozen set is nothing but a
module version of a set here.
So in this our discussion, in our discussion, we have gone through different operations on sets.
We have shown what are the different abled functions, how to define and set, what can be done, what
cannot be done.
And we have discussed everything with some examples here.
Thanks for watching this video.