← Back to challenges

Reformatting the Date

PythonHardstringsregexdates

Instructions

Create a function that converts dates from one of five string formats:

  1. "January 9, 2019" (MM D, YYYY)
  2. "Jan 9, 2019" (MM D, YYYY)
  3. "01/09/2019" (MM/DD/YYYY)
  4. "01-09-2019" (MM-DD-YYYY)
  5. "01.09.2019" (MM.DD.YYYY)

The return value will be a list formatted like: [MM, DD, YYYY], where MM, DD, and YYYY are all integers. Using the examples above:

Examples

convert_date("January 9, 2019") ➞ [1, 9, 2019]

convert_date("Jan 9, 2019") ➞ [1, 9, 2019]

convert_date("01/09/2019") ➞ [1, 9, 2019]

convert_date("01-09-2019") ➞ [1, 9, 2019]

convert_date("01.09.2019") ➞ [1, 9, 2019]

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.