Question: Question 3: Age Filter Write a function that takes a tuple of lists you created in Question 2 and returns a tuple of lists of

Question 3: Age Filter

Write a function that takes a tuple of lists you created in Question 2 and returns a tuple of lists of people whose ages are less than or equals to given threshold.

def filter_age(lists, threshold):

"""Returns filtered tuple of lists

>>> lists = [['Alexa', 3], ['Betty', 14], ['Mike', 17], ['Marina', 20], ['Robert', 23], ['Siri', 45]]

>>> sorted(filter_age(lists, 23), key=lambda tup: tup[1])

[['Alexa', 3], ['Betty', 14], ['Mike', 17], ['Marina', 20], ['Robert', 23]]

>>> filter_age(lists, 1)

( )

>>> len(filter_age(lists, 45))

6

"""

# Your code is here #

Question 4: Put it back in a dictionary

Write a function that takes a tuple of lists you created in Question 3 and returns a dictionary (with the same keys as in Question 1) that does not contain filtered people.

def names_are_back(lists):

"""Returns a dictionary with filtered people

>>> lists = [['Alexa', 3], ['Betty', 14], ['Mike', 17], ['Marina', 20], ['Robert', 23], ['Siri', 45]]

>>> lists = filter_age(lists, 23)

>>> new_dictionary = names_are_back(lists)

>>> 'Marina' in new_dictionary['name']

True

>>> 45 in new_dictionary['age']

False

>>> new_dictionary['age'].sort()

>>> new_dictionary['age']

[3, 14, 17, 20, 23]

>>> lists = [['Alexa', 3], ['Betty', 14], ['Mike', 17], ['Marina', 20], ['Robert', 23], ['Siri', 45]]

>>> lists = filter_age(lists, 45)

>>> len(names_are_back(lists)['name'])

6

"""

# Your code is 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!