http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
I can think of a few ways of doing it with loops but I'd particularly like to know if there is a neat one-liner.
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
I can think of a few ways of doing it with loops but I'd particularly like to know if there is a neat one-liner.
Combine itertools.groupby
with operator.itemgetter
to get a pretty nice solution:
from operator import itemgetter
from itertools import groupby
key = itemgetter('gender')
iter = groupy(sorted(people, key=key), key=key)
for gender, people in iter:
print '===', gender, '==='
for person in people:
print person