Last active
May 8, 2020 14:11
-
-
Save KarthikRajashekaran/674ade02913d0c3d09f6c25d3463bc34 to your computer and use it in GitHub Desktop.
sort_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Sorting the list of dates | |
''' | |
from datetime import datetime | |
dt = ['01 Apr 2017', '01 Apr 2018', '01 Aug 2017', '01 Aug 2018', '01 Dec 2017', | |
'01 Dec 2018', '01 Feb 2017', '01 Feb 2018', '01 Jan 2017', '01 Jan 2018'] | |
print(sorted(dt, key=lambda x: datetime.strptime(x, '%d %b %Y'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment