Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import groupby
- from pprint import pprint
- months = ['1/2013', '7/2013', '2/2013', '3/2013', '4/2014', '12/2013', '10/2013', '11/2013',
- '1/2014', '2/2014']
- def year_month(date):
- m, y = date.split('/')
- return int(y)*12 + int(m)
- L = [[date for _, date in run]
- for _, run in groupby(enumerate(sorted(months, key=year_month)),
- key=lambda (i, date): (i - year_month(date)))]
- pprint(L)
Add Comment
Please, Sign In to add comment