Guest User

for http://stackoverflow.com/questions/23075453/

a guest
Apr 15th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. from itertools import groupby
  2. from pprint import pprint
  3.  
  4. months = ['1/2013', '7/2013', '2/2013', '3/2013', '4/2014', '12/2013', '10/2013', '11/2013',
  5.           '1/2014', '2/2014']
  6.  
  7. def year_month(date):
  8.     m, y = date.split('/')
  9.     return int(y)*12 + int(m)
  10.  
  11. L = [[date for _, date in run]
  12.      for _, run in groupby(enumerate(sorted(months, key=year_month)),
  13.                            key=lambda (i, date): (i - year_month(date)))]
  14. pprint(L)
Add Comment
Please, Sign In to add comment