Hello, in this video, we will discuss Satz, which is our third data-collection, after we have successfully
completed lists and dictionaries.
So let's start with a quick example of a a collection.
We have a fruitcake collection here and it starts with curly brackets.
And then we have values inside quotation marks divided by comma.
So it looks a lot like a list.
Right.
But there is a visual difference that we can immediately identify that we're dealing with a set and
not with the list, the curly brackets, the curly brackets.
Give it the way that this is a set and not a list.
And this is the first visual difference between a set and a list.
Which brings me to the next topic.
OK, now we're going to discuss what is what are the differences between lists and set.
And I want to talk about it because it's very important from two reasons.
First of all, once you wanted to use it in your code, you need to know the differences between lists,
dictionaries set and tuple because they were invented for a reason.
They're not just there and they're doing the same thing.
No, they have different purposes.
They have different functionalities.
And you need to know the difference between them in order to use them properly.
Whether you want to become a web developer later on or an information web developer or a backhand developer,
it doesn't matter.
Whoever uses Python is to know the difference between these four items.
So I'm going to discuss it a lot in this case.
We'll discuss this and SAT and maybe further along will compare other data collections as well.
So let's start with the first star.
And a list can contain the same value in several cells.
OK, we can create a list and put, for example, banana, apple, berry and banana again.
There's no problem with it.
So the list gives us this ability to have duplicate items inside our cells, while set collection cannot
have the same value in more than one cell.
Well, it basically can have more than one value.
But if we try to use that value, we will fail to do so.
So, for example, if I put.
Another banana item right here and then I'll try to print it.
I will not see two banana items when I printed, I was the only one banana item.
OK, you understand what I'm going to show this.
This thing is a valuable onion set and it's not available on list, this functionality of remains of
keeping a non duplicate items when using the set so you can put duplicate inside the set.
But once you try to extract it, you will fail to do so.
OK, the different the second difference is liste is in order the collection, meaning he has an index
and cell values can be accessed by index while set in.
The other hand is in an ordered collection.
Same as a dictionary and does not have an index value for each cell.
So as you recall in dictionary, we started the lecture by saying, hey guys, this is an unordered
list, meaning it does not have a index for each cell and list does have a index for each cell.
We can access cell number zero, cell number two or whatever.
While dictionaries and sets does not have this index parameter or index feature, you might say, in
them.
OK, so the third difference we already discussed said is written with curly brackets and in a list
at least we'll use around brackets.
OK, so this is the third difference and the last one inset.
Once an item is created, you cannot change it.
OK, if we try to recall from our lectures regarding lists and dictionaries as well, the same.
So in lists and dictionaries, there's no problem to change the value of the cell.
We can do whatever manipulations upon the inner values they are to change them and without any problem.
But here in said, you cannot change the value.
And I'm sure there are thousands of cases where developers need this feature or they need to create
a certain collection that will be permanent and cannot be changed.
So this is the fourth difference between leased and set.
And before beginning the section, I said there are two reasons and I explained only I explained only
one.
I said only the first reason.
And the second reason is you eventually going to go to interviews, OK?
And once you put the python in your resume, you obviously going to be asked about it.
And this question is really high percent that it will come up because it's a tricky one.
All right.
For example, tell me two differences between a list and a set, and you need to really know your thing
and to know the the difference between them to answer it correctly.
OK, so it's really important to know these things.
This is what makes a difference between a mediocre developer and a a ninja developer.
OK, and I want you to be ninja's by the end of this course.
And this is why I'm giving you this extra information, which is not only like three examples and practice.
You have also additional knowledge here, like background knowledge regarding development and features.
And this is very important.
OK, so one more thing.
As you can see here in the headline, you do not have basics in the title.
And this is because set contains already some elements that we've been walked through in lists and dictionaries.
So this this data collection and theory will be shorter.
OK, there are some topics which are longer, for example, dictionaries and some are shorter.
So this one is a bit shorter.
OK, so now let's head over to the next topic and see some quick manipulations and things that we can
do with set.
OK, so first of all, how to access items in a set so we cannot access a set sell-by index, as we
mentioned already.
But what we can do is to check if it exists by using boolean statement.
And why do I need what do I mean by that?
So if we want to know whether a banana item is inside a set, we should use the following action.
OK, so we have this data collection up here and we have a banana item here inside the cell.
So we want to know whether.
The banana item is inside the set, the set and collection, so we just do the following thing, we
just write a print because we want some output to know if it's there or not.
And then we want to do the following thing.
We want to use the key word in.
OK, so what this means basically is it's a key word, OK?
It's a save the word.
And this word means like a question mark for us.
I'm saying it for us to understand, like those banana is in fruits, that collection.
The answer is Boolean is a boolean value.
So it's a true or false value.
So in this case, banana is in fruit collection, so the output will be true.
OK, so this is how you verify for certain element is inside the set collection.
All right.
Our following topics will be Loop's and using Loop's.
We can extract all the values out of every data-collection, but we haven't studied Lupe's yet.
So here you can only just verify this point, only verify for certain items inside the set for there
aren't.
We'll learn how to extract values further in the next videos.
OK, so next in line is how to delete items of a set so we can remove items from a set by using the
remove action or the discard action.
So basically they are the same.
So it's really simple.
You just mention the SEP collection, then use the remove action keyword and then use the item that
you want to remove.
OK, and now let us see how to add items to a set, OK, so we can only add or remove items, but we
cannot change items so we can remove items from SL.
By using sorry, we can add items to it to a set collection by using the action would add or update.
OK, they are the same, so just mention the sad collection and then use the add keyword and use the
value that you want to add.
It's pretty simple, right?
OK, and one last thing, as we already discussed, regarding duplicates.
All right, so let's see the following example.
OK, so we will have duplicate items inside that.
Once printing it, Python will ignore duplications and will print only one of the duplicated items.
So a quick example.
Once having this set collection will try to print it.
But pay attention.
You have banana and another banana right here.
So if we print it out, we will have only one banana value.
All right.
I cannot assure you that the first item will be printed all the time because Python arranges its memory
inside our computer in a certain way.
And as we mentioned earlier, this is an unordered list.
So there's no indexes here for zero one two.
There's no such thing.
So we cannot assure that this value always will be printed and this value will be ignored.
But we can assure that only one of the banana items would be printed out as circulation does not tolerate
duplications.
OK, this it covers about the theory regarding said.
And let us go to the next video and see some examples in the code.
All right.
Bye bye.