Hello guys.
So we are going to continue our discussion with respect to Python.
And now we are going to start data structures in Python.
Some of the most common data structures that are used in Python programming language are like lists,
tuples, sets and dictionaries.
So in this series of videos, we are probably going to discuss about all these topics.
In this video we are going to focus more on list.
Uh, so let me just go ahead and show you what is the video outline.
So first of all, we will, uh, go ahead and show you how to I will go ahead and show you how to create
a list.
Then I will also show you accessing list items, modifying list items, some of the amazing list methods
that we use.
Then we have operations like slicing list.
How do I how do we iterate over list?
You know by using for loop and all.
Then along with that we'll also be seeing list comprehension.
And then we will be seeing about nested list.
All these things will be covered with lot of practical examples.
And I'll also be talking about what are the common errors that we will be getting.
So before I go ahead, first of all, uh, let us go ahead and just see the definition of list.
So here you can see list are ordered mutable collection of items.
Right.
Ordered mutable collection of items.
What does mutable collection of items basically means?
Uh, like all the items that are present in list, we can actually change it.
Okay.
Um, and they can contain items of different data types also.
Right.
So these are the two main proper properties with respect to list.
Uh, first of all, they are ordered mutable collection of items.
And they can contain items of different different data types.
So let me just go ahead and let me show you that.
How do you define a list?
Let's say I create a variable called as list.
And if I use this two brackets.
And before that don't forget to select a kernel.
So right now I've selected the kernel based on the environment that I've actually created.
So here you can see over here when I write list with some this empty square braces.
And if I go ahead and print the type of this variable this will give us an empty list.
Right.
So this is a class type of list.
So in order to create a list it is very much simple.
You can just use this empty brackets, right?
Um, now if I want to add elements in the list, uh, let's say that I want to go ahead and create it.
Like I may have multiple names over here.
Let's say I have Krish, I have, um, Jack, I have Jacob.
Right.
So this is basically a list of names.
Okay.
I may also have other elements, like I may have one, two, three, four, five.
Any number of elements.
I may also have different different data types of elements over here.
So here if I go ahead and go ahead and print names.
So it is giving me a name error because I did not write names.
So here you can see that I'm able to get a list of elements right.
So this is how a list is.
Let's say that I go ahead and create a mixed list.
Mixed mixed underscore list list.
And here let's say my first is a number, second is a string, third is a floating point right.
And fourth is a Boolean variable.
Right.
So I may define any types of data type.
And I may also print this.
So let me just go ahead and print mixed underscore list.
So I hope you got an idea about how to properly create a list of items.
Right.
So one is directly using this particular empty brackets.
Or you can also go ahead and add elements over here.
Um with respect to and any, any kind of elements, any different different data types of elements you
can basically add.
Okay.
Now let's talk about accessing accessing list items.
How do we access the list elements.
Right.
So let's say that I uh I create a fruits, right?
Let's say that I'm going to create a fruits element like a list of fruits.
Let's say like apple.
It can be banana, it can be cherry, it can be um, kiwi.
It can be um, pomegranate.
Pomegranate.
Okay.
Or let me just write a simple.
Okay, let's go ahead and see.
Uh, cherries already written.
Um, Apple.
Banana.
Cherry.
Kiwi.
Um, okay.
I, I'm not able to remember more fruits names.
Right.
So let us just keep it till here, okay.
Or.
Okay, fine.
I finally I got one guava.
Right.
So I'm just going to go ahead and create this list of elements.
So here is my list of elements over here.
Now uh, let's say that I want to go ahead and display Apple.
Right.
So in order to display it all I have to do is that just go ahead and right roots uh fruits.
And here you can probably see that I can actually use indexing.
Right.
So whenever we create the elements inside a list okay.
So here this first fruit is basically present in the zeroth index.
Then this is present in the first index.
Second index.
Third index fourth index.
So similarly all the indexes uh when I probably say all the indexes in Python starts with zero.
If you know about our programming language, all the indexes over there starts with one number one.
Right.
But here we are specifically going to use um zero is the index over here.
Right.
But uh if I really want to just display Apple right.
So I will just go ahead and write fruit of zero, right.
If I'm actually trying to print this.
So let me just go ahead and write print Fruits of Zero.
It is not nothing but apple.
Let's say I want to probably get fruit of uh, um in middle cherry.
Right.
So this will become 012.
So if I go ahead and write fruits of two.
So I will be able to get apple and cherry.
And there are some amazing techniques with respect to indexing also.
So, uh, let's say that I want to pick up guava, right?
So I can also go ahead and write print.
Um, yeah.
One way is that I can go ahead and take Y01234.
So I can probably go ahead and write fruits off fourth index I will be able to get guava.
Now this go can also be taken through a different way.
So let me just go ahead and write.
So let's say that I'm going to write print of, uh, fruits.
Let me just, uh, see and show it to you over here.
So let me just go ahead and write Fruits of Fruits of.
Okay.
And now in this particular case, let me just go ahead and write minus one.
Let's see what will happen.
See, minus one is nothing, but it is basically talking about the last element itself.
Right.
So I think I should be able to get both right.
So this is the amazing thing with respect to fruits, right.
Uh, sorry.
This list.
Right.
You are able to probably retrieve any fruit or any items inside this list just by using simple indexing.
Okay.
Now let me just show you one more way of printing some set of fruits elements.
So if I go ahead and write fruits okay.
And you know, if I just use the index one okay I'll be able to get banana.
So I'm getting banana zero one.
I'm getting banana over here.
But what if I have a requirement?
I need to get all the elements from banana till guava.
Right.
So if I go ahead and just make one simple change over here, right.
What I will do, I'll say write fruits one colon.
Right?
One colon basically means from one first index till the end index because I'm not giving anything after
the colon.
So if I just go ahead and execute this here you can see banana cherry kiwi guava right.
So this is one way right now let me do one thing.
Let me just go ahead and print fruits one colon.
And let's say I want to get all the elements till this kiwi index one.
So here you have zero one.
So right two three.
Right.
So now if I go ahead and write one colon three, that basically means it is just going to pick up this
first index.
Second index.
It is not going to pick up the key index.
Right.
Uh and now if I go ahead and display it.
So here you can see banana and cherries there.
That basically means the third index is not getting picked up till the third index everything will get
picked up right.
So if I don't write any element over here.
So it is just going to take it completely till the end.
Right.
And uh, here also, uh, what I can actually do, let me just go and show you one more thing.
So if I go ahead and write, print off fruits, uh, minus one colon right now, if I go ahead and execute
this, you can see minus one colon basically means from minus one element till colon.
Right till colon means till the end.
And this is just my last element over there okay.
But if I just go ahead and write -1 or 2 let's say second index.
So here I can see that you have to please observe here minus one is nothing but this specific element
right.
Two is this right.
But I'm not talking about all these elements.
Now if I go ahead and write minus one to -3 or -3.
Right.
Now here also you'll be able to see this indexing is obviously a little bit confusion okay.
There is a little bit of confusion over here because when I'm picking up the minus one element this
is it is giving us.
But I'm saying from -1 to -3, right.
So there is no such element.
And we'll talk more about this kind of examples and how to do this kind of indexing.
Also when we are further discussing about many things as such.
Right, right now don't worry about this.
Otherwise you'll get more confused over here.
Uh, I'll just keep it like this.
I'll remove this particular code for some time and let later on when you'll be see in the series of
videos, will also be talking about those kind of indexing.
Okay.
Now, uh, perfect.
Till here.
I think, uh, we have, uh, learned many things over here.
Now, what I will be showing you is that how you can modify the list elements?
Okay.
So let me just go ahead here and show you modifying the list elements okay.
Now modifying the list elements is very simple.
Let's say that I want this is my fruits right.
So this is my fruits I want to make sure that I replace banana with something else right now.
Banana you know it.
It is in first index.
Right.
So if I go ahead and write this it is in first index.
Let's say from this I want to probably change this into watermelon okay.
And now I will just go ahead and print my fruits.
Right.
So in that specific index I'm writing watermelon over here and I'm actually displaying it.
Now you can see my fruits has changed banana to, uh, to watermelon.
Right.
So this way in the indexing also, you can directly go ahead and probably replace this particular values.
Right.
So this is how you modify uh any elements that is present over here.
Not only that, let's say I want to go ahead and write like this.
Fruits okay.
Fruits one colon okay.
So one colon is basically giving you this answer.
Now if I go ahead and just write here, please replace everything with watermelon.
Now if I go ahead and see fruits.
So here you can see uh, I'm getting this error.
Uh let's see what is the problem.
Uh, watermelon.
Okay.
Now what it has done is that from this particular index, from this particular index, it has replaced
with this particular word.
Right.
But here it is not considered as a word.
Instead, it is taking this as character by character.
We will also be seeing how we can add word to word.
Right?
So in in in list you have some amazing methods like append and all.
We'll be talking about it as we go ahead right now okay.
Just after this section itself.
Right.
So this is one of the problem that we see right now.
Let me do one thing.
Let me again, uh, use that same fruits over here that I've actually defined.
Okay.
But you understood the problem.
What has happened over here as soon as I said one colon.
Right.
So from first index it has just added w a t r.
So it is not just considered this as a single word.
Instead it is considering character by character and it is adding it.
Okay, so let me just go ahead and define my fruits again.
Okay.
Now let me just go ahead and discuss more about amazing thing that is called as list methods.
Okay.
Now this list methods is quite beautiful.
We'll see to it and uh, we'll be learning more about it okay.
Now let's say I want to, as I said, right.
I want to append an element inside this okay I want to add one element at the end let's say.
So for this I will go ahead and write fruits dot append.
And here let's say I want to append orange okay.
Okay.
Now once I write that basically means this will add an item okay.
To the end.
Okay.
It will basically add an item to the end.
Okay.
And uh, if I just go ahead and print my fruits, you'll be able to see this.
Right.
So now here we'll be able to see apple, banana, cherry, kiwi, guava and oranges over here.
Right.
Now let's say that I have a requirement that I want to probably append any element at a specific index.
Okay.
So let's say I want to add, um, let's say I want to add watermelon in this first index okay.
And right now in the first index banana is there.
So what I will do I'll say fruits dot insert okay insert.
Insert and I will give the index number.
The first element will be the index number.
And the second element will be whatever item I want to put let's say banana okay.
And then I'm just going to print fruits.
So here you can see apple banana banana okay.
Banana was already there I guess.
Yeah banana was there.
Let me do one thing.
Let me add watermelon also.
Okay.
So so in the first index I'm just going to add watermelon.
So here you can see apple watermelon banana banana banana because I have added one time right.
Let's say that I hate two bananas are there.
I want to remove this.
So I will go ahead and write fruits dot remove.
So remove is another inbuilt function uh that is present inside this.
So here I'm going to basically write banana okay.
And now if I go ahead and print fruits okay.
So here you can see banana has gone right now but we don't have one more additional banana.
Okay.
Uh, let's say I want to also remove and um, let's say uh, see whenever we are using this remove.
Right.
It is basically removing the first occurrence of an item.
Right now, let's say I want to remove and return the last item.
Return the last item.
Okay.
Let's say I want to do this.
Uh, what do I mean by this?
Let's say I go ahead and use one amazing inbuilt function which is called as pop.
Okay, now pop basically means it is just going to pop the last element that is present in that particular
fruit.
Uh, and it is going to return us.
Right.
So here I'm going to write pop underscore fruit okay.
Is equal to.
And let me just go ahead and print it.
So I'm going to print it over here.
And let me just go ahead and write pop fruits okay.
And, uh, let me just print it.
Okay.
Let's, uh.
Because at the end of the day, once, I probably, uh, print this and I'll also print the remaining
items that are there in the fruits.
Okay.
So here you can see orange has been popped.
Why?
Because the last element in this list of fruits was orange.
When orange was popped from this particular orange got removed.
Okay, remove and return the last element.
That is how you can specifically do it.
And for that we use an inbuilt function called as pop.
Okay, now let's say that I want to get an index of any fruit right based on the name of the fruit.
So if I go ahead and write fruits dot index.
And here let's say that I want to use, uh, cherry, I want to get the index of the fruit called a
cherry.
Okay.
Cherry.
And this will basically be my index.
And let me just go ahead and print the index.
Now, if I go ahead and execute, you can see that cherry is basically present in 012 three third index.
So I am able to get the output okay.
Uh, again one more thing is that, uh, let me just go ahead and do one thing.
Fruit fruit dot append, or I will try to insert in the second index.
Banana okay.
Banana is already there.
And now let me do one one more inbuilt function.
I'll just go ahead and write fruit dot count.
And here I will just go ahead and write.
Sorry, it should be count.
I will just go ahead and write banana okay.
Okay.
And let me just print this.
Okay.
Now what is going to happen is that you'll be able to see it will just count the number of elements.
And obviously after inserting this banana right now, if you see inside my fruits there are two bananas,
right?
Banana and banana.
So it is just counting that.
How many number of items this specific uh, in this particular list it is there, right.
So here I'm just showing you different, different inbuilt function just by using a list of items.
And uh, here you can see I've shown you a lot of coding with respect to this okay.
Now I may also do something like this.
I may sort this entire list of items.
So if I go ahead and write fruits dot sort.
So here you'll be able to see.
Now if I go ahead and print this fruits you'll be seeing apple banana Banana.
Cherry.
Guava.
Kiwi.
Watermelon.
So automatically based on.
So in in short this will this will sort the list in ascending order.
Okay.
It is just going to sort all the list in ascending order.
And finally here you have fruits dot reverse reverse in another function which will reverse all the
elements over here.
Now if I go ahead and do this right now, you can see the all the list of the elements will basically
get reversed, right?
So this is nothing, but it reverse says the list.
Okay.
And just I'm showing you what all different different inbuilt functions are basically present over here.
Okay.
And then uh, finally if I want to clear the entire list I can go ahead and write fruits dot.
Clear.
clear.
Right.
And now if I use this inbuilt function.
So this will remove all items from the list.
Okay.
Now if I go ahead and print fruits.
So here you can see I'm getting an empty list.
So till now we have discussed about mainly uh, if uh, if I go ahead and show you with respect to the
video outline, uh, we have understood about creating list, accessing list items, modifying list
elements.
Uh, then we discussed about list methods.
Now we are going to discuss about slicing list.
So let's go ahead and discuss more about slicing list.
So guys now let's go ahead and talk more about slicing lists.
So before that I will go ahead and make some cells.
Uh so there is a shortcut.
Just press escape and a you will be able to create as many number of cells as you want.
Okay.
Now what I'm actually going to do is that I am just going to take this numbers.
Okay.
So I'm defining these numbers 123456789 ten.
Now I will just go ahead and write some print elements.
Let's say print numbers two colon five okay.
now let's talk about more numbers.
Oops.
Colon five okay.
Okay I didn't close this brackets.
So that is the reason it was giving me an error.
No worries.
Now we'll go ahead and write print numbers five colon.
And along with this we will also go ahead and see print numbers.
Double colon two okay double colon.
So here we are also learning about double colon.
Single colon I've just given you an idea about it.
But we'll also see with respect to double colon.
And then we'll also go ahead and print our numbers double Double colon minus one.
Okay.
Now just pause for a second and just try to imagine in your mind like what will be the specific outputs
okay.
And then we will discuss further okay.
So here you can see two colon five.
It is very simple 012 from 2 to 5 elements.
So two uh 345 is basically getting displayed 012345.
So this three elements will get displayed.
Colon 512345 will get displayed.
So it is basically coming over here till five.
Then you have 6789 from five colon to till the end.
Now this is very much important.
Double colon two.
What does this basically mean.
And double colon two basically means from all the elements from first.
And this two will be taken as a step size.
Right.
So we will jump two steps ahead.
Like from here we'll jump one two then three will get displayed again.
Jump two steps five will display from again.
From this jump to two steps, seven will get displayed again.
Jump over here.
Nine will be getting displayed.
So double colon.
See if I really want to make you understand about double colon.
So I will go ahead and write double colon.
Double colon basically means all the elements.
Right now if I am writing okay fine.
Uh let's give the test step sizes one.
Then.
Also, I'll be getting the same output if I give the step size to two.
So double jumps will be happening.
Right?
This is basically the step size.
Then if I write three then again three steps like from here one two jump and third uh whichever will
be the element that will get displayed.
So four 710 right.
So I hope you got an idea about it.
Now double colon one basically means what.
Okay.
So double colon one double colon is nothing, but it is all the elements minus one okay.
From previous take all the elements one by one and display it.
If I go ahead and again write something like this.
Let's say I go ahead and write numbers okay.
Double colon minus two.
Write some form back every two numbers.
Right.
It will skip every one number and display the other number over here.
Right.
So this is basically called as a slicing.
And uh.
Uh, some of the operations will be involved in slicing.
Whenever we want to retrieve some results we want to modify them, do something right so we can actually
use it right now coming to the next thing is iterating over list.
Okay.
Now I have already shown you how to iterate over strings.
Similarly you can also iterate over list, right?
So for that also again I will be going and using for loop.
Let's say I will go ahead and write for fruit for fruit in fruits.
Right.
And I will just go ahead and inside and print all the fruit items that I have.
Right.
So here one by one right now no fruit items is present or what.
Okay, okay I have cleared that fruits.
Right.
So let me do one thing.
Let me just take numbers over here so that I will be able to see through it.
Right.
For number in numbers.
Right.
So numbers is also a collection over here.
List of collection list of elements.
So 123456789 ten okay.
So this is also there.
Let's say I want to iterate all this list with indexes also.
So I want to iterate iterating with index.
So for this I can use for index, comma, fruit, fruit or index.
Sorry for index comma number in numbers.
Now once I use this numbers right.
Obviously see if I'm directly using this numbers.
I know this is a list, but if I want index information.
Also I have an inbuilt function in Python which is called as enumerate okay.
And if we specifically use this enumerate that basically means we are also going to get the index number.
So if I go ahead and print index comma number, now you'll be able to see all the indexes.
So this is my zeroth index.
The first element is present in the zeroth index.
Then I have two which is present in the first index then three in the second index, four in the third
index, five in the fourth index, six in the fifth index, seven in the sixth index, eighth in the
seventh index, nine in the eighth index, and ten in the ninth index.
So I have all these things.
And just by using this inbuilt function, you get an excess of the index number.
Also along with the list of elements that are present in that particular list.
Okay, so this is one amazing thing about uh, you know, you can also iterate over the list.
You can also iterate along with the index.
Right now let's go ahead and talk about one more amazing thing, which is basically called as list comprehension
okay.
Now list comprehension.
Now guys, let's let's consider that, uh, I want to do something right.
I want to probably, uh, let's say I'll write a for loop for x in range for x in range.
Let's say I'm going to write ten.
And here, uh, what I'm actually going to do is that I'm going to probably create a list element.
Let's say I'm going to create a list empty elements.
And then I will go ahead and write list dot append.
And let me just go ahead and do this okay.
So just imagine what I've actually done.
Uh, here inside this for loop I'm squaring every number and I'm appending in this particular list.
Right.
And finally I can go ahead and print this particular list okay.
So in short this is a code that I've actually written to square every numbers inside this particular
range of numbers.
Right.
So I'm getting 01249 16, 25, 36, 49, 64, 81.
Now see imagine in this line of code, right?
I've written 3 to 4 lines right over here.
I have, first of all, initialized an empty list.
Then I'm putting a for loop.
Then I'm performing this specific operation.
What if I can perform this entire list operation?
Because everything is happening inside a list itself, and we are creating a new list also over here,
right?
Obviously, if you're creating your list again, new list over here, again, playing with different
different elements, more memory will be required.
So Python actually helps us to play with list comprehension.
Now in list comprehension it tells you that you can perform all this operation right within a list itself.
Right.
So now see this observe over here.
Now I will go ahead and write for x in range ten.
Right.
So here if I go ahead and execute this uh okay.
Right now it is giving me an error because it is invalid syntax I get it okay.
Now let's let's do this okay.
So first I have written for x in range of ten.
So this is basically iterating through this.
Now the next thing is that what kind of operation I'm performing.
So I want to perform x square.
So here if I go ahead and write x square.
So list comprehension basically has two important things what we want as an output and what is the kind
of operation that we are doing.
Right.
So see this is doing some kind of operation.
So that needs to be displayed.
And this is basically my iteration.
So both of them are combined.
If I go ahead and execute this you will be able to see that in a single list.
I am able to get this specific answer.
So here.
What did I do?
I did not have to create other list, item or list elements as such, right?
All I did is that I probably, uh, you know, executed my code within a line of code.
And what I really want is x square.
I have written it in forward right now.
Let's go ahead and see more examples with respect to list comprehension.
So guys we have just seen one example.
And I hope I know that you may be having some kind of confusion.
So it is a better way that if I really want to make you understand about list comprehension, first
of all, let's talk about a specific syntax like what kind of syntax we specifically use.
Okay.
Now uh, the basic syntax okay.
Let me just make this as a markdown okay.
Markdown over here okay.
Let's comprehension.
Okay.
And this is important.
So that is the reason I'm also going to show you the syntax over here.
Okay.
First of all the basic syntax okay.
Now basic syntax is nothing.
But it looks something like this expression for item in iterable.
Right.
So that is what we have done for item in iterable which is traversing everything.
And this expression is going to perform on all the single items.
Okay.
This is the basic syntax okay.
Now I may also have other option like with conditional logic okay.
If I want to apply some logic over here.
So with conditional logic the expression looks a little bit different.
Okay.
And let me just show you this particular expression also.
Okay.
So here you can see expression for item in iterable if condition.
Also I can put.
So I'm putting if condition over here.
So any kind of conditional logic is there.
You have to probably put it at the last iterate whatever iteration you really want to do, you want
to put in the center and any kind of expression that you want to perform.
You can put it in the starting.
Okay.
Now based on this we will try to see some kind of example.
Okay.
So but remember this this is super super important okay.
And you have to use with respect to this itself.
Right.
So let's consider one example.
So let me go ahead and write basic list comprehension.
Okay.
Let's say I want to do a square off all the number okay.
Square off all the number okay.
Square off a set of numbers.
So I will write for x or for num in range of ten.
Right.
And for every of this number I just need to do num square.
Right.
Square.
Done.
Now if I go ahead and print this in short what I'm actually going to get, I'm going to basically get
the square of this number.
Now what condition I have applied over here basic syntax for item in iterable.
And then I have expression okay.
Now coming to the next one okay.
Let's say let's consider with list comprehension with condition okay a specific condition over here
okay.
And let's say I will try to find out from a list of elements which are which are basically even numbers.
Okay, okay.
Which are even numbers.
Now, let's say if I go ahead and write in for loop for I in range ten, okay.
If I go ahead and write, if I colon two is double equal to zero, right, then what I have to do print.
Or I will probably create a list and I'll append all the even elements.
Right.
So let's say I have created a list an empty list over here.
And now what I'm actually going to do I'm going to basically write list dot append list dot append.
And here I'm going to basically write my I right.
So finally if I go ahead and print my list, you'll be able to see that all the even elements will come
right till this particular ten number.
Right.
But here you need to see how do I convert this into list comprehension.
And I showed you one expression with conditional logic.
Expression is over here for item in iterable is here.
And if condition is over here now the same thing I will try to convert this into list comprehension.
So I will write for I or for num in range.
Range 20 okay or ten okay I have to display the number itself.
So I will right number.
I don't need to even apply any expression.
But here I will go ahead and write one if condition.
I will say hey if num percentile two or modulus two is double equal to zero.
Now this basically becomes my event underscore numbers.
Right now here I do not have to even create a new list.
Right.
All I'm doing it in one single line of code.
So this way my execution will happen quicker, right?
It will be faster.
So I hope you are getting this as an idea.
Okay.
Now one more.
One more thing, is there?
Okay.
One more, very important, uh, thing is there, which is again a type of list comprehension you can
basically say which is called as nested list comprehension.
So let me just go ahead and write it down.
So here you have something called as a nested list comprehension okay.
And it is good to know all these things.
Guys I am trying my level best so that you will be able to understand multiple things.
Okay.
So here you can see and here you can see now what is so different when compared to this okay.
Now here we are iterating through two different iterables.
So for item in iterable one for item two in iterable two, then we are writing an expression.
So that basically means if I have two lists.
And then on top of that two list I want to perform any kind of list comprehension.
Then I can use this nested list comprehension.
So let me show you one perfect example.
Okay.
Let me just go ahead and write it over here and let me write it as nested list.
Comprehension.
Okay.
Comprehension.
So let me go ahead and create my list one.
And this will be 123 okay.
Or I'll take one more element for let me say this is my list two which will be nothing but a.
b, C, d.
Okay, so these are my four elements.
Now let me do one very simple thing.
Okay I will try to make a pair pairs of list one and list two elements okay.
So first of all I will iterate through list one.
So let me just go ahead and write for I in list one okay.
Then I will iterate through list two for j in list two okay.
And then I have to pair it right.
Now for pairing I will be using a tuple I have not discussed yet about a tuple, but I'm just going
to take this I and j and pair it together.
Okay, just write it in this way.
Okay, now you can see.
Or if you don't want to like write like this you can also use list over here Okay, let's see whether
this will work or not.
And now I'm just going to print pair okay.
Appear appear have written pair okay so here you can see one comma one comma b one comma c one comma
d two comma two comma b two comma c two comma d.
So it is just doing all the pairing 1A1B1C1D2A2B2C2D.
So this is what is happening.
First of all this will iterate right with respect to one element.
Then it will iterate all the elements right.
We can also write this in this particular way also.
Right.
But again lot of lines of code we really need to write.
But this is really really powerful.
And here you can actually see with the help of nested list comprehension we are able to do it right
now in Python.
Also you have lot of inbuilt key functions right.
So we can actually use list comprehension.
List comprehension.
With function calls you can create your own custom function and all.
But right now I'm going to show you some uh inbuilt functions okay.
So inbuilt function will try to see.
So list comprehension with this let's say and I will I will show you the code over here.
So here I have words like hello world, Python list comprehension.
Now see everybody focus.
So I'm writing for words in words and I'm just saying length of word.
Right.
So it is just going to give us the length of word over here.
Right.
And how easily we are able to see this particular output.
Right.
And this looks amazing.
Right.
And most of the things are basically very much simple over here right now.
Uh, there is also one more list comprehension technique where you can use else block also.
So, uh, I will give you that as an assignment.
Please make sure that you do it.
But don't worry as we go ahead and run, learn more about the tuples and all there.
Also, we'll be covering more about it, but I hope, uh, you got an idea with respect to list comprehension.
And uh, this was all about the discussion with respect to list.
And, uh, I think I tried my level best to cover almost each and every thing.
Okay.
And at the end of the day, you really need to try more and more to understand more.
Example, unless you don't practice.
Uh, I don't think so.
You will be able to do any perfection in this.
Right.
So more examples, more things.
But at the end of the day, I would like to give the conclusion of this lesson and probably talk about
it, you know, because list is something really important.
So the list.
So here you can see I have given some conclusion with respect to the list comprehension, a powerful
and concise to create list in Python.
They are syntactically syntactically compact and can replace more verbose looping construct.
Understand the syntax of list comprehension will help you write cleaner and more efficient Python code,
right?
So yes, uh, this was it.
Uh, I will see you all in the next video where we will be talking about the next data structure.
Thank.