Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
when_is_friday solution in Clear category for When is Friday? by dannedved
from datetime import date
def friday(day):
# First, we convert the input string into a list of integers.
# We reverse the list, so that 'year' comes first and 'day' last.
day_int = list(map(int, day.split(".")[::-1]))
# We parse the list as 'date' constructor arguements (we use an asterisk to unpack the list).
# We use the date.weekday() method to find out what day it is (represented as integer - 0 stands for Monday, 6 for Sunday).
w_day = date(*day_int).weekday()
# From Monday to Friday (represented as 4), we count days until Friday in the same week.
if w_day <= 4:
return 4 - w_day
# For Saturday and Sunday, we count days until the next week's Friday (represented as 11, i.e. 4 + 7).
return 11 - w_day
July 21, 2020