Created
November 27, 2012 12:49
-
-
Save sputnikus/4154081 to your computer and use it in GitHub Desktop.
How to sort list of dates in format '13 July 2011'
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
>>> 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