Skip to content

36. Reformat Date Strings

Difficulty: Easy · Topic: Data wrangling

A form collects dates as day/month/year text, like "01/03/2026" for 1 March 2026. Write to_iso(dates): return a list with each date in ISO format ("2026-03-01"), in the same order.

Example: to_iso(['01/03/2026', '25/12/2025']) gives ['2026-03-01', '2025-12-25'].

Your code runs in CPython on our servers against 5 tests, including hidden ones.

Sample test

to_iso(['01/03/2026', '25/12/2025'])

Expected: ['2026-03-01', '2025-12-25']

Hints

Hint 1datetime.strptime(text, "%d/%m/%Y") reads the text and raises ValueError when it does not fit or is not a real date. Careful: %M is minutes, %m is the month.
Hint 2.date().isoformat() writes YYYY-MM-DD.
Hint 3Catch ValueError per value and append None.

Learn the concepts

More Python problems

All Python problems