+ result = defaultdict(dict)
+ for tag_list in tag_lists:
+ for tag in tag_list:
+ try:
+ result[tag.category][tag.pk].count += tag.count
+ except KeyError:
+ result[tag.category][tag.pk] = tag
+ for k, v in result.items():
+ result[k] = sorted(v.values(), key=lambda tag: tag.sort_key)