title: What is the most efficient way to traverse a tree in Python?
body: <p>Assuming I have a list of objects that have the following fields</p>
  
  <p><strong>parent</strong></p>
  
  <p><strong>value</strong></p>
  
  <p>and this defines a tree structure, similar to a directory tree.</p>
  
  <p>I want to traverse the list in a pre-order fashion. What's the most efficient way?</p>
  
  <p>Normally, in other (more imperative) languages I would iterate the values, finding the ones with no parents, then for each, iterating again for every object whose parent is the one I'm currently looking at and so forth, but is there a cleverer way to do this in Python?</p>