Skip to content

Instantly share code, notes, and snippets.

@sputnikus
Created November 27, 2012 12:49
Show Gist options
  • Save sputnikus/4154081 to your computer and use it in GitHub Desktop.
Save sputnikus/4154081 to your computer and use it in GitHub Desktop.
How to sort list of dates in format '13 July 2011'
>>> import time
>>> format = '%d %B %Y'
>>> sort_dates = lambda y: sorted(y, key=lambda x: int(time.mktime(time.strptime(x, format))))
>>> dates = ['13 July 2011', '13 August 2011', '3 October 2010', '13 July 2012']
>>> sort_dates(dates)
['3 October 2010', '13 July 2011', '13 August 2011', '13 July 2012']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment