Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

1 3 9 .

Answered: 1 week ago

Question

ANALYZE the emerging emphasis on employee recognition.

Answered: 1 week ago