Created
August 11, 2023 16:05
-
-
Save tiagodavi70/b6319a7c239d7bbfcd8bff6a9b9ee231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from pprint import pprint | |
from copy import deepcopy | |
def arvore(): return defaultdict(arvore) | |
def dicts(t): return {k: dicts(t[k]) if type(t[k]) is not defaultdict else dict(t[k]) for k in t} | |
def apresentar(d): | |
for k, v in d.items(): | |
if isinstance(v, dict): | |
d[k] = apresentar(v) | |
return dict(d) | |
def adicionar(arv, caminho): | |
for no in caminho: | |
arv = arv[no] | |
organizacao = arvore() | |
organizacao["Presidente"]["Diretoria"]["Gerencia"]["Loja"] | |
organizacao["Presidente"]["Diretoria"]["Infraestrutura"]["Externa"] | |
organizacao["Presidente"]["Diretoria"]["Infraestrutura"]["Interna"] | |
organizacao["Presidente"]["Diretoria"]["Marketing"] | |
pprint(apresentar(organizacao)) | |
localidade = arvore() | |
adicionar(localidade, "Brasil>Pará>Belém>Pedreira".split(">")) | |
localidade["Brasil"]["São Paulo"] | |
localidade["Brasil"]["Maranhão"] | |
pprint(apresentar(deepcopy(localidade))) | |
del localidade["Brasil"]["Pará"] | |
pprint(apresentar(deepcopy(localidade))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment