Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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