Created
June 7, 2019 09:27
-
-
Save H4medRostami/8a76f8bc1c713b0aa6a45f0f55550d0c to your computer and use it in GitHub Desktop.
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment