Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Most Frequent Weekdays by neshta85
import calendar
def most_frequent_days(year):
days = {i: 0 for i in range(7)}
for i in range(1, 13):
for a in list(calendar.Calendar().itermonthdays2(year, i)):
if a[0] > 0:
days[a[1]] += 1
return [calendar.day_name[k] for k, v in days.items() if v == max(days.values())]
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"
Jan. 14, 2019