Oh yes and welcome back to another class of our course about the complete introduction to fight on programming.
So today we are going to still talk about lists but instead of just talking about the basics we are
going to talk about list functions.
So as we said the beginning of this squares there are many types of functions that exist.
You can apply function to strings you can apply functions to numbers you can apply functions to well
you have many types of functions on Python but you can also apply functions on lists.
So what exactly are list functions.
So technically it's just simple manipulations that you can do on lists by yeah.
Well writing down functions so functions can for example.
I don't know help you add something in your list can help you let's say copy and past your list can
help you count the number of elements that you have in your list.
So what I personally done you have you have hundreds of different functions but what I personally have
done I simply look for the most popular functions that exists about the lists and I selected five of
the most used functions for lists.
Well the most use that list functions that are used in Python.
So basically what we will do today is I will show you I'll give you an introduction to functions to
list functions.
And if you guys are interested you can after that go on the internet and just find out many other list
functions and try them out by yourself.
So we'll see it's not very hard to understand.
All right.
So let's start the first thing that we are going to talk about will be the function answer.
So let's say for example the first thing they'll ask you is write down a book well two lists so a list
of numbers and a list of a list of strings.
So we'll start by the first function.
This function will help us insert something in a list.
So let's say for example in this list of words where this is this list is called food and I want to
insert another type of food right here.
So what exactly I will do.
So let's say for example I want.
Well I'll start by printing this list.
I want to print my list that is food.
All right.
So if I print my list I will receive this this answer.
So Hamburger is a juice price let's say for example I want to insert something in my list since lists
can have millions of different elements.
And I'm interested right now to insert one element in this list.
So to be able to do this what I will do I will use the insert function.
So how this function works.
Very simple.
You write down the name of your list dot insert.
Then you will add the index in which you want to insert your your your element.
So let's say for example I am I want to insert another word right here.
So right here will be the element number 2 so 0 1 and 2.
So this will become the element number two.
So the index well the object or the element.
So let's say I am writing so I'm gonna write down the index number two and then I want to insert let's
say in this case I'm interested to insert spaghetti for example.
So spas getting great.
So what I just did is I insert the in the index number to the words spaghetti and if I run my function
if I run my up as you can see I will have hamburger pizza and spaghetti right here and not forget one
thing in Python we always start counting by 0 0 0 1 2 3 4.
So this will become the segment element that we have or the second object.
All right.
So this is the first type of function.
This is the first function we'll talk about the second one will be very simple.
It's simply delete delete.
So let's say you want to delete all your list.
So this list you want to delete it for example.
So what you can do is simply delete everything manually or just write down delete right down the delete
function.
In this case how it will look like.
So let's say for example you write down your food and the word says it it's going to be the clear function.
So very simple.
You write down clear you open and close the parenthesis.
So what we ask Python so as you can see right here we ask Python to clear our func to clear our to clear
our list food.
So here we have our list and we ask Python to clear it.
So when we run the app as you can see we have nothing in our list.
The same thing as if we have deleted everything.
All right.
So right now you know how to add things in your list and how to delete things in your list.
Right now let's say you want to put a list into another list.
I'll just take this out.
So let's say you want to integrate the prices into the foods.
So in this case what will happen.
You want to put those two lists together.
So let's say for example you have one list of food and you have another list of food and you want to
put them all together in one simple list.
So what we'll use as a function to be able to do this there is a function called extend.
So you will simply extend your initial list and add more elements at once so you can add another list
to your first list you can add variables to your list.
So how exactly this works.
Very simple.
So we start with our first list which is food.
So write down food we click on that then the function as I said will be extended so that it will be
this one and what you will write down inside your parentheses will be the second list that you want
to add.
So in this case we want to add the price the prices.
So right now we have our food that extend and the same list.
So if we run our app as you can see the food the food the list the list food became the list food and
the list prices.
So this is a way that you guys can put two lists together simply by using the extend function.
So this is another way that you can.
This is another function that you guys can use to be able to work with lists that you can see it's not
something that is hard to work with.
But once again those are some manipulations that you guys can do with your lists.
All right.
Let's say right now that you guys are interested to find.
Let's say what what is the index of a certain certain type of food right here.
So let's say for example you guys are looking for pizza because here it's simple.
We only have five plus one six elements.
But let's say you have hundreds of elements and you're interested to find one of those.
So it's like in Excel you or you will lose them.
You will use the view lookup function in Python.
What we have we have the index function.
So in this case what you guys will do is very simple.
So we will use our print function and let's say we are looking for pizza.
So what exactly we write down we'll write down our print and what exactly we are asking Python to do.
We will take our list and that from this list will simply write down index.
Our function will be index.
And from here we'll write down the element that we are looking for.
So we are looking for pizza.
We write it down and then we simply run our function.
So as you can see pizza is the first element right here.
So we have zero then we have one.
If we write down another element which in this case will be juice normally we should receive no for
why no sorry.
Why.
Because we have a hamburger as number zero pizza as number one juice as number three and spaghetti as
number two which makes sense because we put it spaghetti right here all right.
Next function that we are going to talk about will be the challenge function.
Let me just show you how it works.
Let's say for example you have one type but what you have right here is the only ones.
But let's say you have pizza five times so what you guys will do simply take the pizza and you can copy
and paste it let's say at the end of the list twice.
All right.
And that will do the same thing for Jews as well so we'll try it multiple times so you guys will understand
how this function works.
All right great.
So right now what we want to do we want to print the number what we want to count the number of times
each of those words is repeated.
So what we will do we'll do this for all the words.
So in this case we have hamburger as well so we just copy and paste it
and we have sushi great.
So yes I have copied and pasted everything.
So what we will do will use a function that is called the count function.
In this case how it's written very simple once and we'll write down our friend function right here and
we will ask Python to go in our list and to count how many times this element is repeated.
So in this case let's say we want to know how many times pizza is repeated and we run our up as you
can see pizza is repeated three times if we want to do the same thing for Jews we can do it
we run our app and as you can see Juice is repeated three times if we do the exact same thing for sushi
is
as you can see it's run two times.
Not forget the eyes it's very important that you write the exact same word right here.
So let's say for example I start to shoot up the letters as you can see it's zero because I don't have
sushi with capital letters right here.
So very important you need to write down the exact the exact word.
If not it's just not gonna work.
All right.
Let's thing we are going to talk about today will be copying lists in this case what we guys.
What you guys want to do let's say for example you want to copy one of those lists.
So it's very simple how this works.
Let's say you want to create another list.
So we'll name it
let's let's name it random random and random will be equal to our food copy.
So in this case food copy so very important you open and close parentheses.
So it will be the copy of the list food.
So in this case we want to have the copy of food.
So we simply write down food that copy.
In this case while it will copy food plus prices that copy.
So what I just did I asked by Don to create another list that will be random that includes the list
of food copy and price copy.
And in this case if I run my app just a print
say I want to print everything.
So in this case I'll print random right.
All right.
So as you can see I have my list right here all my lists.
So I have my first list and I have my second list.
Once again it's another way to well to create a list.
So right now I just copied the food and I copied prices so as you can see guys.
Those are the basic manipulations that you can do with lists.
Those are some basic functions that exist.
You have many many others.
If you guys are interested to learn more about list functions once again I suggest you to simply go
on Internet and type list functions.
You'll have hundreds of them that will appear same thing format functions in some.
Same thing for a string of functions.
But my goal right now is really to show you what exactly are those functions and how they work.
So right now you understand all this and you can go to the next step of our course.
That's it for this class guys.
And see all in our next class.