Question: Create a function called happybirthday that takes as input three dictionaries, name_to_day, name_to_month, and name_to_year, and combines them into a single dictionary month_to_all that contains

Create a function called happybirthday that takes as input three dictionaries, name_to_day, name_to_month, and name_to_year, and combines them into a single dictionary month_to_all that contains the month as the key and the name, (day, year, age) as the value of the month_to_all dictionary. For this problem, you may assume that the current year is 2022 - i.e. age = 2022 - year. Specifically, your function should:

  1. Have input arguments happybirthday(name_to_day, name_to_month, name_to_year), expecting name_to_day as a dictionary mapping a name (string) to a day in the month (integer), name_to_month as a dictionary mapping a name (string) to a month (integer)and name_to_year as a dictionary mapping a name to a year(integer). You may assume all inputs to be valid.
  2. Create a new dictionary month_to_all where the keys are all the months contained in name_to_month (note: if a month does not appear in 'name_to_month', it should not be included in 'month_to_all'), and contains information in the following structure name, (day, year, age), with (day, year, age) being the tuple of values from name_to_day, and name_to_year corresponding to name. Note: the value we want in this new dictionary is a tuple, where the first element of the tuple is the name from 'name_to_month' and the second element of the tuple is a tuple of day, year, age.
  3. Return month_to_all.

For example, typing in

name_to_day={'jack':14,'helen':2,'zach':20} name_to_month={'jack':4,'helen':2,'zach':10} name_to_year={'jack':2014,'helen':2002,'zach':1969} 

should return

{'4': ('jack', (14, 2014, 8)), '2': ('helen', (2, 2002, 20)), '10': ('zach', (20, 1969, 53))}

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!