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 tanya
from datetime import date
def most_frequent_days(year):
"""
List of most frequent days of the week in the given year
"""
result=[x[1] for x in sorted(set([(date(year,1,1).weekday(),date(year,1,1).strftime("%A")),\
(date(year,12,31).weekday(),date(year,12,31).strftime("%A"))]))]
return result
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert most_frequent_days(212) == ["Wednesday","Thursday"]
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"
print ('Done')
Jan. 24, 2019
Comments: