Question: Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are 0), int (day of the month 1 to

Language: PYTHON

Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are 0), int (day of the month 1 to 28) Returns: dates: list of tuples Description: Imagine that you have a favorite weekday, and want to see if certain days fall on that weekday. Using the calendar module from the Python standard library , write a function which takes in a list of tuples formatted like [(month, year), etc.], your favorite weekday, and a day of the month. Using the module, find the weekday of each (month,year) tuple at the day of the month that was passed in (1-28). If that weekday is equal to your favorite weekday, add the tuple to a list to be returned at the end of your code. Assume the day of the week will lie within 0-6 inclusive and the day of the month will be always be valid.

(Hint: look at calendar.weekday method)

Test Cases:

>>> dates = [(1, 1999), (7, 1980), (3, 2018), (12, 2003)] >>> print(favorite_day(dates, 6, 20)) [(7, 1980)]

>>> dates = [(10, 1803), (1, 2019), (6, 1964), (11, 1920), (2, 2011)] >>> print(favorite_day(dates, 0, 1)) [(6, 1964), (11, 1920)]

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!