Recently came across a situtuation where I was trying to display a dictionary of dictionaries of lists in a django template. In the python code, the data structure was built like:
@property
def nested(self):
from collections import defaultdict
data = defaultdict(lambda: defaultdict(list))
for x in self.a_list_of_objects:
data['key'][x.an_attribute].append(x)