Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First2 solution in Clear category for The Most Frequent Weekdays by tigerhu3180
from datetime import date
DAY={
0:'Monday',
1:'Tuesday',
2:'Wednesday',
3:'Thursday',
4:'Friday',
5:'Saturday',
6:'Sunday',
}
def most_frequent_days(year):
"""
List of most frequent days of the week in the given year
"""
#the start day and the end day of year is 'xxxday'?
start=date(year,1,1).weekday()
end=date(year,12,31).weekday()
#build a bridge from 'start' to 'Sunday' same as 'Monday' to 'end'
#find which day occured most,then that could be answer
list1=[i for i in range(start,7)]
list2=[i for i in range(end+1)]
#return common or put both list together when no common
return [DAY[i] for i in list1 if i in list2] or sorted([DAY[i] for i in list1+list2])
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert most_frequent_days(2399) == ['Friday'], "1st example"
assert most_frequent_days(1152) == ['Tuesday', 'Wednesday'], "2nd example"
assert most_frequent_days(56) == ['Saturday', 'Sunday'], "3rd example"
assert most_frequent_days(2909) == ['Tuesday'], "4th example"
March 8, 2018