title: How to get all children, grandchildren, ... from this list?
body: <p>I've <code>items</code> in a parent-child-relation. Every child knows its parent but a parent doesn't know its children nor its grandchildren:</p>
  
  <pre><code>items = [
    {'id': 1, 'parent': None},
    {'id': 2, 'parent': 1},
    {'id': 3, 'parent': 2},
    {'id': 4, 'parent': None},
    {'id': 5, 'parent': 4},
  ] 
  </code></pre>
  
  <p>I'm trying to build a dict which includes all item ids with a list of all its children, grandchildren and so on:</p>
  
  <pre><code>all_children_of_items = {
    1: [2, 3],  # 2 = child, 3 = grandchild
    2: [3],
    3: [],
    4: [5],
    5: [6]
  }
  </code></pre>
  
  <p>My current approach only considers the children, not the grandchildren:</p>
  
  <pre><code>all_children_of_items = {}
  while True:
    change = False
    for item in items:
      if item['id'] not in all_children_of_items:
        all_children_of_items[item['id']] = []
      if item['parent']:
        if item['parent'] not in all_children_of_items:
          all_children_of_items[item['parent']] = []
        if item['id'] not in all_children_of_items[item['parent']]:
          all_children_of_items[item['parent']].append(item['id'])
    if not change:
      break
  
  </code></pre>
  
  <p>Current result:</p>
  
  <pre><code>{
    1: [2], 
    2: [3], 
    3: [], 
    4: [5], 
    5: []
  }
  </code></pre>
  
  <p>Any idea? Thanks in advance!</p>