Skip to content

Instantly share code, notes, and snippets.

View AlexanderGreyFox's full-sized avatar

AlexanderGreyFox

View GitHub Profile
@AlexanderGreyFox
AlexanderGreyFox / to_tree_func.py
Created April 20, 2022 14:23
Написать функцию, строящую дерево по списку пар id (id родителя, id потомка), где None - id корневого узла.
def to_tree(source: list):
i = 0
result = dict()
node = result
while i < len(source):
parent = source[i][0]
child = source[i][1]
if parent is None:
result.update({child: {}})
i += 1