Created
July 21, 2014 22:28
-
-
Save apalala/494a84da76e543ab3bca to your computer and use it in GitHub Desktop.
Complex Lookp
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
# already sorted | |
for name, group in itertools.groupby(db_iter, key=lambda x: x[0]): | |
total_sales = 0 | |
number_of_sales = 0 | |
earliest_sale = None | |
latest_sale = None | |
for _, amount, date in group: | |
if amount is not None: | |
total_sales += amount | |
number_of_sales += 1 | |
if date is not None: | |
if earliest_sale is None: | |
earliest_sale = date | |
latest_sale = date | |
employee_stats = dict( | |
total_sales=total_sales, | |
number_of_sales=number_of_sales, | |
earliest_sale=earliest_sale, | |
latest_sale=latest_sale, | |
) | |
report(name, employee_stats) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment