def BuildAndDisplayAdUnitTree(root_ad_unit, all_ad_units):
  tree = {}
  for ad_unit in all_ad_units:
    if 'parentId' in ad_unit:
      if ad_unit['parentId'] not in tree:
        tree[ad_unit['parentId']] = []
      tree[ad_unit['parentId']].append(ad_unit)

  DisplayAdUnitTree(root_ad_unit, tree)
Create an ad unit tree and display it.
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201508/inventory_service/get_ad_unit_hierarchy.py/BuildAndDisplayAdUnitTree