Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| A warning occurred (42 apples) | |
| An error occurred |
| def list_to_tree(input, none_and_holes=True, source=[0]): | |
| """Transforms nestings of lists or tuples to a Grasshopper DataTree""" | |
| from Grasshopper import DataTree as Tree | |
| from Grasshopper.Kernel.Data import GH_Path as Path | |
| from System import Array | |
| def proc(input,tree,track): | |
| path = Path(Array[int](track)) | |
| if len(input) == 0 and none_and_holes: tree.EnsurePath(path); return | |
| for i,item in enumerate(input): | |
| if hasattr(item, '__iter__'): #if list or tuple |