I have some products that need to be assigned categories. I went through some nested dictionary methods, however I just want to know an effective way to use the tree structure.
Examples of categories correspond to the following image, the indicated depth is also the maximum depth of the tree.

I want to take the name of the elements in the tree, look for it in a string, use it as a substring and store it in the temp list if it exists.
For example: I will search for MUV, SUV, Sedan words in a string, if SUV exists, I will keep updating temp = [Car, SUV]. After that, walk the same way as the SUV node to the end of the tree. So the list at the end will look like this [Car, SUV, Window, XYZ]
, 4 .
, 30000 .