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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started