Skip to content

Instantly share code, notes, and snippets.

@victorono
Created March 16, 2016 13:43
Show Gist options
  • Save victorono/e0c1ffb2cd694da53232 to your computer and use it in GitHub Desktop.
Save victorono/e0c1ffb2cd694da53232 to your computer and use it in GitHub Desktop.
Sort list of date strings
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
all_dates = ['09-2012', '04-2007', '11-2012', '05-2013', '12-2006', '05-2006', '08-2007']
sorted(all_dates, key=lambda x: datetime.strptime(x, '%m-%Y'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment