Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10-liner: Counter & defaultdict solution in Clear category for The Most Frequent Weekdays by Stensen
DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
from datetime import datetime, timedelta
from collections import defaultdict, Counter
def most_frequent_days(year):
date = datetime(year, 1, 1)
d = defaultdict(int)
while date < datetime(year + 1, 1, 1):
d[DAYS[date.weekday()]] += 1
date += timedelta(days=1)
return sorted([i for i in d if d[i] == max(d.values())], key=DAYS.index)
Nov. 20, 2020
Comments: