Let's go ahead and explore collections library and art.
First thing we're going to talk about of course is list dark of course.
It's supposed to be a modern language which means has to be succinct and very straightforward if you
will.
So they you notice that the syntax is it's very concise and easy to read.
Right.
So in this case here for us to create a list right the array if you will we just save our I want to
hold this list.
And then we're going to create our square brackets as such and then inside that's where we actually
put all of the items.
Now this is the deciding moment right because we whatever we put first it will dictate what types this
list will hold.
So if I go in say one and say to say three four and then I say 10 I make these numbers a little bit
different
hand like that.
There we go.
Now we have a list.
Let's do it now.
How do we access for instance each one of these.
We said that in order for us to access we have to go and find where each item lives.
In this case what index we want to access so we know all starts at index 0 so this is going to be in
0 1 2 3 and 4.
So if I say I want Number two that means I have to go to index 1 right.
I can go see print and I see a list in order for eyes for me to get the index.
I also have to use the square brackets as such and pass on one index is all I'm saying here saying go
to list variable and fetch whatever is inside of index 1 which means two should get to run.
And there it is there's two.
Obviously if you won the last one here we can just go ahead this is zero.
One two three four and go ahead and say four.
It's going to run.
We should see 10.
Now the cool thing about this is that there's a few methods or properties we can actually retrieve from
the list right few methods.
That gives us information about the list one of which is still length.
So I can actually come down here I can say print because the last one when you say Dot.
Look at this.
It turns out we can also add remove last and so forth.
Like I said everything in dark is indeed an object.
This is why we have these capabilities.
What we want here is just the length.
Now what is the line length is how many items we have inside of our list now.
Length and index are Torelli that are different things.
Now index is 0 1 2 3 4 laugh is 1 2 3 4 5 right.
How many spots we have will have one spot.
Two three four or five spots right.
So if I run like this we should see five because that's the length.
If we add another number to 6 Well we will see that indeed we'll have 6 now because we have this information
we can actually find the length of our array or list here.
What we can do certain things we can actually go ahead and say let's see if I want to get the last item
of this list let's suppose that we have thousands of items thousands of numbers inside of this list.
Well we'll get to just go ahead and say last dot land minus one.
That will give us the last more.
Let's see.
Is that true.
There we go 56.
So what this is doing is that while we know that inside of our straight or square brackets here we have
to pass the index right now.
In this case we're saying OK the index has to be the length of the entire list.
What is life.
One two three four five six right.
And we're going to subtract 1 to get last month.
So if the length is five then the last one is going to be the fourth item.
If the length is 6 right.
If this is six miners one is five which is going to be 0 1 2 3 4 5 which is 56 game.
That's a trick that you can always use if you want to get the last item in in an array or list.
In this case the next obvious thing to learn to do is how do we then iterate through a list if that's
what's going to happen often.
Right.
We want to be able to iterate through our array or any array.
Well simply we can go ahead and say for game for loop I say int in zero.
Now check this out and see pi is last then list that laugh because I know the length right.
Because we have this opportunity to get the length of a list that's very handy.
That way we don't have to worry about the length constantly actual length of the array.
So if the array changes the length to 2000 then we don't have to come here and change the number.
Right.
And they can go ahead and say I play splice and then I can just go ahead and say print I can make it
a little more special.
I can say Index tains
expression here is going to say list and I'm going to pass the I search.
OK so now I'm going to go through the length of this array.
I keep saying all right but same thing let's call list to be more congruity with dark language the length
of our list here.
So if it's 6 and 1 2 3 4 5 6.
So it's going to be while I for eyes less than six We're going to keep incrementing and inside here
we're going to go ahead and pass the eye of the 0 it's going to be zero contains and go to the zeroth
index.
It's going to be 10 and goes back and forth until this is not true.
OK.
Which will break for a loop run.
And there we go say that zero contains 10.
Is that true.
Yes.
Next one contains to 13 and so forth.
Fifty six is the index five can be a little more creative here than go ahead and say for instance if
the top here is going to say if you list high right ampersand two or percentages would say equal to
zero.
Remember this
I'm going to say print
this expression.
So we need to ensure
content is multipole of to me Be succinct here.
Let me just put it there.
Say Alice
like that and say not to get.
So what are we doing here.
Well as we go through our list we're going to go ahead.
In fact all of the numbers inside of each of inside of each index and we're going to check to see if
it's a multiple of two right.
The remainder here remember if it's multiples to say that item is multiple of two and we're going to
print it else we're going to say index is index I contains that number and multiple multiples to just
a very simple little thing here.
Let's see.
Get rid of all of this or we don't end up with a lot of junk skip run.
OK 10 years multiple to see is multiple of two is indeed two is multiple too next two contains 13 and
is not multiple of 2 x 2 0 1 2 Yes 13 is not a multiple of two indeed.
The fourth to 10 is really six is a multiple of two.
There we go.
Very cool.
So we're able to create it really quick fun a little application here that leverage is lists and for
loops.
And of course the module or the remainder operator here.
Very cool.
So go ahead and play around with this concept.
And I will see you in the next video.