Solution Review: Highs and Lows
Review the solution for the "Highs and Lows" exercise.
We'll cover the following...
We’ll discuss two solutions to this problem.
Solution 1: Using filter
and lambda
Let’s explore the first solution to the problem of highs and lows:
Press + to interact
def count_low_high(num_list):if (len(num_list)==0):return Nonehigh_list = list(filter(lambda n: n > 50 or n % 3 == 0, num_list))low_list = list(filter(lambda n: n <= 50 and not n % 3 == 0, num_list))return [len(low_list), len(high_list)]num_list = [20, 9, 51, 81, 50, 42, 77]print(count_low_high(num_list))
Explanation
Here’s a line-by-line explanation of the code for the problem highs and lows:
Line 1: Defines a function named
count_low_high
that takes one argumentnum_list
, which is expected to be a list of numbers.Line 2: Checks if the length of ...
Access this course and 1400+ top-rated courses and projects.