Task:
You are given a year as integer (e. g. 2001). You should return the most frequent day(s) of the week in that year. The result has to be a list of days sorted by the order of days in week (e. g. ['Monday', 'Tuesday'], ['Saturday', 'Sunday'], ['Monday', 'Sunday']). Week starts with Monday.
Input: Year as an int.
Output: The list of most frequent days sorted by the order of days in week (from Monday to Sunday).
Preconditions:
- Week starts on Monday.
- Year is between 1583 and 4000.
- Calendar is Gregorian.
Examples (input -> output):
* 2427 -> ['Friday']
* 2185 -> ['Saturday']
* 2860 -> ['Thursday', 'Friday']
Solution:
from calendar import weekday, day_name
def most_frequent_days(year):
print(sorted( {weekday(year, 1, 1), weekday(year, 12, 31)} ))
for day in sorted( {weekday(year, 1, 1), weekday(year, 12, 31)} ):
return [ day_name[day] ]
print(most_frequent_days(2023))
Most Frequent Weekdays Solutions | Codewars
No comments :
Post a Comment