In the 3. Larger List exercise, how would we go about solving the question using the max() function applied over the len() of the list?
The question states
Write a function named larger_list that has two parameters named lst1 and lst2 .
The function should return the last element of the list that contains more elements. If both lists are the same size, then return the last element of lst1 .
I know the solution but was wondering if it can be solved this way. My thought process was to return the name of the list with the most elements when comparing 2 or more lists using the max function, and then call the last element of that list
What if the problem extends to 10 lists instead of 2? We can’t just keep using if statements
One will by this point appreciate that max() is of marginal use in terms of tracking the objects. Where only two objects are involved it is pointless, tbh. We have to run the len() function on both objects, regardless.
The max function deserves further investigation which will prove useful in reaching the answer to your question. How do the docs describe it?