nodes: 0, module; 1, function_definition; 2, function_name:dependency_sort; 3, parameters; 4, block; 5, identifier:dependency_tree; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, comment:"""
      Sorts items 'dependencies first' in a given dependency tree.
  
      A dependency tree is a dictionary mapping an object to a collection its
      dependency objects.
  
      Result is a properly sorted list of items, where each item is a 2-tuple
      containing an object and its dependency list, as given in the input
      dependency tree.
  
      If B is directly or indirectly dependent on A and they are not both a part
      of the same dependency cycle (i.e. then A is neither directly nor
      indirectly dependent on B) then A needs to come before B.
  
      If A and B are a part of the same dependency cycle, i.e. if they are both
      directly or indirectly dependent on each other, then it does not matter
      which comes first.
  
      Any entries found listed as dependencies, but that do not have their own
      dependencies listed as well, are logged & ignored.
  
      @return: The sorted items.
      @rtype: list
  
      """; 12, assignment; 13, assignment; 14, pattern_list; 15, call; 16, block; 17, identifier:sorted; 18, identifier:sorted; 19, list; 20, identifier:processed; 21, call; 22, identifier:key; 23, identifier:deps; 24, attribute; 25, argument_list; 26, expression_statement; 27, identifier:set; 28, argument_list; 29, identifier:dependency_tree; 30, identifier:iteritems; 31, call; 32, identifier:_sort_r; 33, argument_list; 34, identifier:sorted; 35, identifier:processed; 36, identifier:key; 37, identifier:deps; 38, identifier:dependency_tree
code: def dependency_sort(dependency_tree):
      """
      Sorts items 'dependencies first' in a given dependency tree.
  
      A dependency tree is a dictionary mapping an object to a collection its
      dependency objects.
  
      Result is a properly sorted list of items, where each item is a 2-tuple
      containing an object and its dependency list, as given in the input
      dependency tree.
  
      If B is directly or indirectly dependent on A and they are not both a part
      of the same dependency cycle (i.e. then A is neither directly nor
      indirectly dependent on B) then A needs to come before B.
  
      If A and B are a part of the same dependency cycle, i.e. if they are both
      directly or indirectly dependent on each other, then it does not matter
      which comes first.
  
      Any entries found listed as dependencies, but that do not have their own
      dependencies listed as well, are logged & ignored.
  
      @return: The sorted items.
      @rtype: list
  
      """
      sorted = []
      processed = set()
      for key, deps in dependency_tree.iteritems():
          _sort_r(sorted, processed, key, deps, dependency_tree)
      return sorted