0:00
Hey everyone, welcome back to our Python
0:02
exercise series for beginners. So
0:04
today's is a very short and sweet and
0:07
really fun exercise. In the previous
0:09
episodes, we have worked on list. It's
0:12
what is list, why do we use it, its
0:14
built-in functions. Uh we have checked
0:17
in the previous episodes whether the how
0:19
to check whether the list is empty or
0:21
not. So today we are going to compare
0:26
So we are going to learn how to compare
0:28
and it sounds really simple but trust me
0:32
there are some cool little details to
0:34
notice here. So here is the task. We'll
0:37
ask the user to enter two list and then
0:41
we will split those items into actual
0:44
lists in Python that we have did it
0:47
already in the previous episode itself
0:49
and then we'll check if both lists are
0:51
the same or not. At the end the program
0:54
will say the lists are equal or the
0:57
lists are different. All right, let's
0:59
write the step by step together.
1:23
enter the first number or list
1:42
equal to input. Same thing
1:53
list separated by comma.
1:58
So if you check the previous episode
2:01
here we actually split the user input
2:03
but you know what we can actually use
2:05
split here also. right here
2:09
in the same way we'll do it. Here we are
2:27
And now we'll compare the list. It's
2:29
pretty simple. So step two
3:04
the lists are different.
3:12
now when you run this
3:25
and maybe cabbage any anything in the
3:29
Second list apple, banana,
3:36
list are equal. Okay.
3:42
What if you give some other
3:55
this time? Strawberry,
4:10
Now enter. See the lists are different.
4:12
Okay, let's see what's going on here.
4:15
First we are asking the user input. So
4:17
we said enter the first list separated
4:19
with comma and we are adding it inside
4:22
the list by splitting them with comma.
4:26
Okay. And then so Python whenever sees
4:30
comma it will split the text or whatever
4:33
the element there and make it into a
4:36
separate items list items. It separated
4:39
the first list items and the second list
4:41
items with comma and then it created two
4:44
beautiful lists. If you want you can
5:04
or anything. It could be list can attach
5:07
anything. And 1 2 3. See, you can see
5:12
two list. It is creating ABC or 1 BC 1 2
5:16
3. Okay. So, next we are checking
5:19
whether the items in the list are same
5:21
or not. How list one equal to list two?
5:24
By just this simple condition list one
5:28
double equal to list two. If list one is
5:30
double equal to list two then it will
5:33
check whether the lists are equal or
5:39
If both the lists are exactly same then
5:41
Python will say the lists are equal if
5:44
otherwise it will say the lists are
5:46
different. It's that simple. Sometimes
5:49
you give the same elements in the list
5:51
but sometimes you give the order
5:53
different like for example 1 2 3 and
6:00
So 1 2 3 and 3 2 1. These are two
6:02
different things. Even though they have
6:04
the same numbers the order is different.
6:07
So it is showing the lists are
6:09
different. Order also matters when
6:11
comparing the lists. And yeah that's it.
6:14
You have just built a simple program
6:16
that compares two list. This may seem
6:18
basic, but understanding how lists work
6:21
in Python is super important and we'll
6:24
be using them everywhere. So, keep
6:26
practicing. Try with different inputs
6:29
and even experiment with uppercase and
6:31
lowerase letters to see what happens.
6:34
All right, I'll see you in the next
6:36
exercise where we'll push our Python
6:38
skills even further. Until then, happy
6:41
coding and don't forget to like, share,
6:43
and subscribe. See you in the next one.