Hello, everybody, and welcome to the practice, they are offset collections, so please open your
project, Invitrogen, which is learning.
All right, just opening right now.
All right.
And then create a new file with a substantial name collections.
SAT practice, all right, first of all, as always, let's leave a meaningful comment for the future.
All right.
So that's Data-Collection set.
Practice.
All right, so first of all, I ask you guys to create a collection of drinks, so let's do that.
So first mission is to create a new set.
Collection of drinks, right?
So it goes like this, drinks curly brackets and then inside quotation marks with both the items as
we learned in the previous lecture, then we have Sprite and then we have.
Beer.
All right, so just be careful, because beer is for 18 plus age, at least in my country.
And now we have water.
And now we have.
Soda.
All right, so like that, and then I asked you to add additional sale containing soda value.
All right.
As you recall, we had like a note here that if you had another sale of soda, we already have soda
sale right here.
So it would be a duplicate and set does not like duplicates.
Right.
But with that said, let's add it.
All right.
Add additional sale with soda value.
So how do we do it?
We just mention the asset collection then that then we have all these options open up for us.
And by chance and we just want to add here a new item.
So we just choose this one.
Add sorry, and we use we choose the add one and the inside here.
We just add whatever we want.
In our case we add soda and after we added soda, let's try to print that print or even go.
By the way, I forgot to print here.
All right.
Said.
Collection brings out.
Right, casting.
And drinks I so want and output for all of our actions, this would be Simon number one, this would
be assignment number two like that.
And printing green.
Printing drinks.
After adding.
An additional solar cell like that.
All right.
So now we do the casting, then drinks, and once we do it, anyone can tell what will happen.
We said that Seth Collection does not like duplicates, so let's try to print it and see what happens.
OK, so this is the first one we see over water, cola, soda and Sprite, and here we see beer, water,
cola and Sprite.
So what what just happened for us?
Nothing happened.
Nothing, because once we use the add action key correction identified that we already have this soda
item inside our collection and it just did not edit at all to our collection.
So this is an important point.
If someone asks you what will happen to a cell collection, if you add additional sale with the value,
with a value that already exist inside the collection.
So your answer would be nothing.
Nothing will happen.
All right.
So after this, we had assignment number three.
And on assignment number three, we had to delete soda out of the set collection.
All right.
So how do we do it?
We just mentioned the collection.
Then we put the dot and now we have all the actions and we just choose a remove here and we inside quotation
mark.
We just mentioned what we want to delete.
In our case, it is soda.
And then let's just try to.
Brent drinks.
After deleting solar cell.
All right, so it's right here and Los.
Plus, SDR drinks and just Clow or so, then just close it, the brackets sprinted.
See what happens right here.
All right, so we have deleted the soda out of the collection.
So as you can see, this also indicates that once we try to add here additional sale, it was not like
invisibly added because we already have one.
So it's like added what we can see it.
It was not added at all.
And why am I seeing it?
Because right here, when we delete it so that we do not see it.
All right.
So again, it's just it's just strongs the fact that it was not added at all.
OK, all right.
So and the third assignment, we just deleted the solar cell out of the collection and now we do not
have it.
And anyone can recall if said collection before we go to the next assignment, which is which is copying.
So that collection.
All right.
Copy said copy the.
The drinks into a new SAT collection, so anyone remembers if a collection is an ordered or unordered
collection and this is important for anyone to remember.
All right.
So if if you recall from previous lectures, we mentioned the differences between the collections and
we mentioned that collection is an unordered collection, meaning it does not have indexes for its sales.
So it's unordered and unindexed, it's not indexed.
So once you try to copy it, let's see what happens.
So you were asked to create rings to collection and copy from the existing one?
Same as we did in list.
If I recall, we already did this copy action.
Right?
So we did this like this.
And let's try to print drinks to all print drinks to set collection.
All right.
And what do you think before you apply this action, can you tell me when you can you tell yourself
to be more accurate and what would happen when we print it?
All right.
So here we see this order.
We see color first and we're inspired then water.
But as I just mentioned, the collection is an unordered and an index collection.
So once I copy it, the important question should be, will it be copied with the same order?
And to answer that question, you need to ask yourselves, is it an ordered collection or is it not?
And we just said that it's not.
So once we print it, let's see what happens.
All right.
As you can see here.
All right.
As you can see and as expected, it was not printed out in the order of what we had in the original
drinks collection because it's an unordered list.
So once we copy it, we're not we cannot be sure that the order will be saved.
It's not going to be safe because it does not have indexes.
So once you copy it in hell is going to break through like chaos because you cannot maintain order in
a collection.
So once you copy it, the order will be break braked.
As you can see here, it's really important part because it's it's like when you tried to use when you
tried to figure out which collection you want to use in your code, you have to take this in in consideration
like you need the index or you don't need index, because sometimes you like to copy your collection
and it's important for you to maintain the order, but sometimes it's not important for you.
So in this case, if you use a copy of a collection, your order will be broken.
It's very important.
I'm trying to bring you to the A game.
I'm trying to bring out the ninja developer out of you mentioning all these little comments that are
very important.
All right.
It's like a simple, simple topic or it's just an additional collection.
All right.
So it doesn't it cannot contain duplicates and stuff.
Yeah, but you have important, important things here that you might be asked in interviews.
And furthermore, when you try when you start coding in your job, once you apply to an already accepted,
you will try to choose a collection for your code, for a mission that you have.
And you need to know these things because this is what differentiates medius mediocre from a ninja or
these little things.
So I'm trying to bring you all the little notes so you will become a professional by the end.
All right.
OK, so now let's go to the fifth assignment.
So your fifth assignment was to print out.
It was a bonus one, by the way.
It was to print the length of the collection.
And as I recall, I mentioned that you need to look it up online.
So it was pretty it's pretty easy to find it.
And I'm just going to give you the answer straight away.
And you just need to you just need to look online how to print the length of a collection.
And the first results will probably give you this, the following result, because you only have one
result for this question.
So look out for like look for the result right now.
All right.
So the length of the collection.
Drinks is is on is, yeah, so what do you do?
So, first of all, there is the key action guyland at the end like that, and then inside you put the
collection that you want, the length of it be print it out.
But now we have here, all right, here we have a integer and this is a string.
So we have a problem.
So we need to cover it with, uh, with a casting for strings.
So we have string, you have length and you have drinks.
All right, let's sprint, let's see what happens.
OK, so we have four cells here.
One is the copy one this one, one, two, three, four.
If I recall, we already use the length and once we studied the lists.
All right.
So we use it already is just a reminder of how to do it.
But again, all right.
This is how you do it.
Just put langue action and inside you put the lay of what you think of what you need to recall.
And around it, you put the casting of string like that.
So you have the number four here.
And actually you have four cells here, one, two, three, four.
So this one is also correct and this is about it.
I think we covered everything that we need to know regarding said collections.
Right.
We practice it here and learn learned lot things.
So we learned that once we add a cell that already exists inside the cell collection, it's not going
to be added like the cold is going to just completely ignore of it.
And after that, when we copied it and we tried to print out the copy, we have seen that chaos goes
goes up because we cannot maintain order in an unindexed collection such such as set.
So once we printed out the drinks, too, did not maintain the order.
And last we had to print out the length of the collection and we saw that we printed out the number
of items that we have successfully.
All right.
So this is about it.
So in the next lecture, we will learn about tuple, which our fourth collection, fourth and last collection.
And once we complete that part, we will be masters in collections and in interviews we can ask you
we can be asked for everything.
And I assure you that you will know all the answers.
If you watched all the theory lectures and practiced all the assignments, I'm sure that you can answer
every question that anyone would ask you.
And that's about it for this lecture.
See you in the next video regarding Topal.
Thank you and bye bye.