Skip to content

Instantly share code, notes, and snippets.

@ruchej
Created May 11, 2022 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruchej/6c0ff4188c2ee04c6fbf956af7f3c622 to your computer and use it in GitHub Desktop.
Save ruchej/6c0ff4188c2ee04c6fbf956af7f3c622 to your computer and use it in GitHub Desktop.
def nace_childs(data, parent=''):
return list(filter(lambda x: x['Parent'] == parent, data))
def nace_code_tree(data, parent='', max_level=4):
nodes = nace_childs(data, parent)
for node in nodes:
if node['Level'] < max_level:
childs = nace_code_tree(data, node['Code'], max_level)
else:
childs = []
node['childs'] = childs
return nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment