def create_tree(parent, list):
    parent['children'] = []
for record in comment_set:
    if record['parent_id'] == parent['id']:
        parent['children'].append(create_tree(record, list[1:]))
return parent
comment_tree = []
for record in comment_set:
    if record['parent_id'] is None:
        comment_tree.append(create_tree(record, comment_set))
Визуализация дерева из оператора SELECT таблицы закрытия?