Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import itemgetter
- rows = [{'address': '5412 N CLARK', 'date': '07/01/2012'},
- {'address': '5148 N CLARK', 'date': '07/04/2012'},
- {'address': '5800 E 58TH', 'date': '07/02/2012'},
- {'address': '2122 N CLARK', 'date': '07/03/2012'},
- {'address': '5645 N RAVENSWOOD', 'date': '07/02/2012'},
- {'address': '1060 W ADDISON', 'date': '07/02/2012'},
- {'address': '4801 N BROADWAY', 'date': '07/01/2012'},
- {'address': '1039 W GRANVILLE', 'date': '07/04/2012'}, ]
- rows.sort(key=itemgetter("date"))
- print(rows)
- # now group by
- from itertools import groupby
- rows.sort(key=itemgetter("date"))
- for date, item in groupby(rows, key=itemgetter('date')):
- print(date)
- for i in item:
- print(' ', i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement