title: What is the efficient way to define and traverse tree in python?
body: <p>I have some products that need to be assigned categories. I have gone through some nested dictionary techniques, however just want to know the efficient way to use the tree structure.</p>
  
  <p>Sample categories are as per following image, the depth shown is also the maximum depth of tree.</p>
  
  <p><img src="https://i.stack.imgur.com/XuTo6.jpg" alt="enter image description here"></p>
  
  <p>I want to take the name of elements in tree search it a string using it as substring and store in temp list if it exists.</p>
  
  <p>For example: I will search for MUV, SUV, Sedan words in string if SUV exists i will store update temp =[Car, SUV]. After that traverse similarly with SUV node until the end of tree. So list at end will look similar  to this [Car, SUV,Window,XYZ]</p>
  
  <p>I am completely new to this data structure hence need some suggestions on defining this 4 level of tree structure and efficiently accessing it.</p>
  
  <p>I am asking for efficient way because this process will be repeated at least 30000 times in program.</p>