'Build a tree from a list of objects

I am trying to build a tree from a list of objects, which are characterised by several properties. Each object can have 3 properties that play a role in building a tree, that is velocity altitude exposure.

#Data structure

class Test():
   pass

tests = []
for el in data:
   test = Test()
   test.velocity = el[0] #100km/h or 120km/h or 140km/h
   test.altitude = el[1] #20m or 40m or 60m
   test.exposure = el[2] #10uSv or 20uSv or 30uSv
   #more data is assigned which is not shown as irrelevant
   tests.append(test)

# I am trying to build a data tree like the one below.
# Obviously it would be different than this one and depend on actual data input.
# Example built statically using anytree

Tests
├── 100km/h
│   ├── 20m
│   │   └── 10uSv
│   ├── 40m
│   │   └── 10uSv
│   └── 60m
│       └── 20uSv
├── 120km/h
│   ├── 40m
│   │   ├── 20uSv
│   │   └── 30uSv
│   └── 60m
│       ├── 20uSv
│       └── 30uSv
└── 140km/h
    └── 20m
        └── 30uSv

Although this problem looks simple (might not be) I just can not figure it out.

Cheers!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source