Created
October 20, 2009 15:58
-
-
Save arsatiki/214369 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 itertools import groupby | |
from operator import itemgetter | |
data = [dict(name="Tyler Bennett", id="E10297", salary=32000, department="D101"), ...] | |
department = itemgetter('department') | |
for dep, persons in groupby(sorted(data, key=department), department): | |
print "\nDepartment", dep | |
print " Employee Name Employee ID Salary Department" | |
for person in sorted(persons, key=itemgetter('salary'): | |
print "%(name)-15s %(id)-15s %(salary)-15s %(department)-15s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment