Question: PYTHON The parents dictionary in the final.py file is a dictionary whose keys are strings (names) and whose values are lists of strings (names). For

PYTHON

The parents dictionary in the final.py file is a dictionary whose keys are strings (names) and whose values are lists of strings (names). For example:

>>> parents['Mark Zuckerberg'] ['Edward Zuckerberg', 'Karen Zuckerberg'] 

The parents of Mark Zuckerberg (the CEO of Facebook) are named Edward Zuckerberg and Karen Zuckerberg.

Complete the ancestors function, so that it returns a list of the ancestors of a person, including the person's parents, grandparents, great grandparents, and so on (assuming those ancestors are listed in the dictionary). Although the parents dictionary as it stands only goes back as far as two of Mark's great grandparents, you should assume that the ancestry information of a person might continue for an arbitrary number of generations.

When completed, here are some of examples of correct output:

 >>> ancestors('Mark Zuckerberg') ['Edward Zuckerberg', 'Karen Zuckerberg', 'Miriam Hollnder', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg'] >>> ancestors('Edward Zuckerberg') ['Miriam Hollnder', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg'] >>> ancestors('Jack Zuckerberg') ['Minnie Wiesenthal', 'Max Zuckerberg'] 

CODE GIVEN: (Must just fill in code that is given! Question is above!)

parents = dict() parents['Mark Zuckerberg'] = ['Edward Zuckerberg', 'Karen Zuckerberg'] parents['Edward Zuckerberg'] = ['Miriam Hollnder', 'Jack Zuckerberg'] parents['Jack Zuckerberg'] = ['Minnie Wiesenthal', 'Max Zuckerberg']

def ancestors(person): # base case if parents.get(person) == None: # you should return something here pass # recursive case else: ancs = parents.get(person) # fill in the rest

# return something at the end

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!