Question: Please define this function in python Restrictions: You must use recursion to solve each problem. Remember, this means that as your code progresses through the

Please define this function in python

Restrictions:

You must use recursion to solve each problem. Remember, this means that as your code

progresses through the problem the same function keeps calling itself on updated

("smaller") tasks until the base case is reached.

You cannot import any module.

descendants(family_tree, name, distance)

Description: family_tree is a dictionary where the key is a person's name (string) and the

corresponding value is a list of his/her children's names (string). The function takes a name and

returns all its descendants that are distance generations apart. Assume that all names (both keys

and values) are unique. However, some names might not have any children.

Parameters: family_tree (dictionary), name (string), distance (positive int)

Return value: list of strings (order of names doesn't matter), and if there are no descendants an

empty list

Example:

descendants({'alex':['bob','chloe','dan'],

'bob':['ellen'],

'chloe':['filip','greg'],

'dan':['hector','iris','jason']

'greg':['olive','paris']}, 'alex', 2) ['ellen', 'filip', 'greg', 'hector', 'iris', 'jason']

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 Programming Questions!