Problem 136046 · easy · Level 01 Prerequisites & Setup

Oldest and Newest Diary Entry

tuples · tuple comparison · strings · py-tuples

A diary app stores the date of every entry as a string "DD/MM/YYYY", always with two digits for the day and the month ("05/03/2024" is the 5th of March 2024). The entries are not in order.

Write date_span(dates) that returns a tuple (earliest, latest) holding the earliest and the latest date, written exactly as they appear in the list. Return None if the list is empty.

The helper diary(n, seed) returns n random dates in this format.

Examples

Input:  dates = ["15/06/2020", "02/01/2021", "30/12/2019"]
Output: ("30/12/2019", "02/01/2021")
Explanation: as strings, "02/01/2021" would come first, but it is the newest date.

Input:  dates = ["01/01/2000"]
Output: ("01/01/2000", "01/01/2000")

Input:  dates = []
Output: None

Constraints

  • 0 <= len(dates) <= 10**5
  • every string is a real date between the years 1000 and 9999

Goals

  • Turn a date string into a (year, month, day) tuple so that comparisons follow the calendar
  • Return two results together as a tuple
Starting Python…