

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Pure Functions
incomplete
2: Pure Function Review
incomplete
3: Reference vs. Value
incomplete
4: Pass by Reference Impurity
incomplete
5: Input and Output
incomplete
6: Should I I/O?
incomplete
7: No-Op
incomplete
8: Memoization
incomplete
9: Referential Transparency
incomplete
10: Pure Functions Practice
incomplete
11: Pure Functions Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Datetimes are infamously a pain in the neck for programming. One of the easier items on the long list of problems is the order of the year, month, and day in a calendar date. Most of the world uses the day-month-year format, but some insane countries use month-day-year because they want everyone else to be miserable.
Refactor the sort_dates function. It currently uses .sort(), which modifies the list in-place (an impure operation). We want to change it to use sorted() with a custom helper function, to sort the dates chronologically without modifying the original list.
When you pass key=format_date, Python runs your helper function on every item to figure out the sort order (using the YYYYMMDD format), but it puts the original dates (MM-DD-YYYY) into the final list.