Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Finally simple solution in Clear category for Days Between by BootzenKatzen
"""
I finally managed to do a one-line solution!
Normally I'd end up doing something like:
date1 = date(*a)
date2 = date(*b)
diff = (date1 - date2).days
return abs(diff)
But I got it in one line this time!
"""
from datetime import date, timedelta
def days_diff(a: tuple[int, int, int], b: tuple[int, int, int]) -> int:
return abs((date(*a) - date(*b)).days)
print("Example:")
print(days_diff((1982, 4, 19), (1982, 4, 22)))
assert days_diff((1982, 4, 19), (1982, 4, 22)) == 3
assert days_diff((2014, 1, 1), (2014, 8, 27)) == 238
assert days_diff((2014, 8, 27), (2014, 1, 1)) == 238
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 30, 2023
Comments: