Question: Python (functional programming, lambda functions) Question 2: filter by name and height In this function, we will be exploring the filter() function in python. Remember

Python (functional programming, lambda functions)

Question 2: filter by name and height

In this function, we will be exploring the filter() function in python. Remember from readings that the filter function will return all elements of a list that satisfies a particular condition. This condition is passed into the filter function as the first argument in the form of a function (named or lambda).

Complete the function filter_by_name_and_height below. The function takes one parameter: people which is a list of dictionaries. Each dictionary in the list has two properties: name and height (height is in inches). Here is a sample structure of the list:

people = [ {'name': 'Andy', 'height': 180}, {'name': 'Bethany', 'height': 100}, {'name': 'Cassidy', 'height': 150} ] 

Complete the function filter_by_name_and_height below to return a list of people (i.e. dictionaries) whose name is greater than 4 characters and whose height is greater than 120 inches. In the example above, only Cassidy's dictionary would be returned since the name attribute is greater than 4 characters and the height attribute is greater than 120 inches. The return value would look like [{'name': 'Cassidy', 'height': 150}] Note: Make sure to cast the output of the call to the filter() function to a list() type since filter() returns a filter_object. Also, make sure to use the filter() function. The autograder will check if you have used the filter() function.

def filter_by_name_and_height(people): """ Returns a list of people (i.e. dictionaries) that have names greater than 4 characters long and whose height is greater than 120 inches. Parameters ---------- people: list of dictionaries Returns ------- A list of dictionaries """ # YOUR CODE HERE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!