code: def sorted_tree(tree):
      return OrderedDict(sorted([(k, sorted(v, key=attrgetter('key')))
                                 for k, v in tree.items()],
                                key=lambda kv: kv[0].key))