Here is the simple solution with Python, datetime.datetime and datetime.timedelta modules:
datetime.datetime
datetime.timedelta
from datetime import datetime from datetime import timedelta def most_frequent_days(year): weekdays = { 'Monday': 0, 'Tuesday': 0, 'Wednesday': 0, 'Thursday': 0, 'Friday': 0, 'Saturday': 0, 'Sunday': 0, } date_format = '%s-%s-%s' start_date = date_format % (year, '01', '01') end_date = date_format % ((year + 1), '01', '01') start = datetime.strptime(start_date, '%Y-%m-%d') while start.strftime('%Y-%m-%d') != end_date: if (start.weekday()) == 0: weekdays['Monday'] += 1 elif (start.weekday()) == 1: weekdays['Tuesday'] += 1 elif (start.weekday()) == 2: weekdays['Wednesday'] += 1 elif (start.weekday()) == 3: weekdays['Thursday'] += 1 elif (start.weekday()) == 4: weekdays['Friday'] += 1 elif (start.weekday()) == 5: weekdays['Saturday'] += 1 elif (start.weekday()) == 6: weekdays['Sunday'] += 1 start += timedelta(days=1) max_value = max(list(weekdays.values())) res = [] for item in list(weekdays.items()): week_name = item[0] week_day = item[1] if week_day == max_value: res.append(week_name) return res
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is the simple solution with Python,
datetime.datetime
anddatetime.timedelta
modules: