Skip to content

Instantly share code, notes, and snippets.

@KarthikRajashekaran
Last active May 8, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarthikRajashekaran/674ade02913d0c3d09f6c25d3463bc34 to your computer and use it in GitHub Desktop.
Save KarthikRajashekaran/674ade02913d0c3d09f6c25d3463bc34 to your computer and use it in GitHub Desktop.
sort_date.py
'''
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