- [Instructor] For this Self Check exercise,
we'd like you to work with a couple of the functions
that we just presented in the preceding video.
First, we'd like you to play around
with the min function, both with and without
the second argument, the key argument.
So we'd like you to create a list called foods,
containing the strings that you see here.
And I've already put that statement
in the notebook here for you to look at.
Then what we want you to do is call the
min function with this list as is.
And in a second statement, we want you
to call the min function with the
strings, such that you can ignore
the case for finding the minimum.
So we did that in the preceding video
by calling the lower function, or method, rather,
on each of the strings in the list
as part of calling the min function.
So that's one exercise.
And then separately, we would like you
to use the zip function, that we just introduced,
to zip together two integer lists and create a new list
containing the sum of the elements
from the corresponding indices in both lists.
So elements at position zero in each list
will be added together, elements at position one
in each list will be added together, et cetera, et cetera.
And you can do that a number of different ways.
In the solution, I'll show you,
we'll use a list comprehension.
But go ahead and give that a shot
and then come back to see the results.
OK, let's take a look at the first exercise up above here.
And again, we're going to create the list
first, so I'll go ahead and do that.
Now the first thing we wanted you to do
was try the min function with the list as is.
So don't worry about the uppercase-lowercase sensitivity.
And based on uppercase, lowercase, again,
the uppercase letters are going to have the smallest values,
so Bacon should be the minimum in this case.
And indeed, it is.
However, if you want to do a case-insensitive comparison,
you have that capability by providing that keyword argument.
So in this case, once again, we're saying
for each string, give me the lowercase string
and use those lowercase strings
to figure out the minimum value in foods.
And, as you can see, apples is
the minimum value in that case.
And of course, we did get different results.
And the reason for that, once again,
is that in the first case, we're doing a pure
lexicographical comparison and we're not
specifying how to modify those elements
for the purpose of comparison.
In the second case, we are saying only
look at these strings as all lowercase letters,
and therefore, we got the case-insensitive
comparison in that example.
And apples came out smallest in that case.
Now as far as zipping goes, here is a zip solution
for a couple of sequences of integers.
In this case, two lists of integers,
one containing 10, 20, and 30,
and one containing one, two, and three.
And of course, we can define those
and assign them to variables.
And they don't have to be lists.
They could be other sequences, such as tuples, et cetera.
So what we're going to do is zip together
the pairs of elements from those,
so 10 and one will be zipped together,
20 and two will be zipped together,
and 30 and three will be zipped together.
For each tuple, as we iterate through them,
we will unpack the tuple into the variables
a and b, and then, in the resulting list,
we will add a and b together to produce the list element.
So if I go ahead and execute that,
we can see we get 11, which is 10 plus one,
22, for 20 plus two,
and 33 for 30 plus 3.