Created
May 11, 2022 12:57
-
-
Save ruchej/6c0ff4188c2ee04c6fbf956af7f3c622 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
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