nodes: 0, module; 1, function_definition; 2, function_name:topological_sort; 3, parameters; 4, block; 5, identifier:dependencies; 6, identifier:start_nodes; 7, expression_statement; 8, expression_statement; 9, function_definition; 10, function_definition; 11, function_definition; 12, while_statement; 13, expression_statement; 14, if_statement; 15, comment:"""
      Perform a topological sort on the dependency graph `dependencies`, starting
      from list `start_nodes`.
      """; 16, assignment; 17, function_name:edges; 18, parameters; 19, block; 20, function_name:in_degree; 21, parameters; 22, block; 23, function_name:remove_incoming; 24, parameters; 25, block; 26, identifier:start_nodes; 27, block; 28, assignment; 29, identifier:leftover_nodes; 30, block; 31, else_clause; 32, identifier:retval; 33, list; 34, identifier:node; 35, return_statement; 36, identifier:node; 37, return_statement; 38, identifier:node; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, for_statement; 43, identifier:leftover_nodes; 44, list_comprehension; 45, raise_statement; 46, block; 47, subscript; 48, subscript; 49, assignment; 50, assignment; 51, call; 52, identifier:child; 53, call; 54, block; 55, identifier:node; 56, for_in_clause; 57, if_clause; 58, call; 59, return_statement; 60, subscript; 61, integer:1; 62, subscript; 63, integer:0; 64, subscript; 65, binary_operator:in_degree(node) - 1; 66, identifier:node; 67, call; 68, attribute; 69, argument_list; 70, identifier:edges; 71, argument_list; 72, expression_statement; 73, if_statement; 74, identifier:node; 75, call; 76, comparison_operator:in_degree(node) > 0; 77, identifier:CyclicDependency; 78, argument_list; 79, identifier:retval; 80, identifier:dependencies; 81, identifier:node; 82, identifier:dependencies; 83, identifier:node; 84, subscript; 85, integer:0; 86, call; 87, integer:1; 88, attribute; 89, argument_list; 90, identifier:retval; 91, identifier:append; 92, identifier:node; 93, identifier:node; 94, call; 95, not_operator; 96, block; 97, identifier:list; 98, argument_list; 99, call; 100, integer:0; 101, identifier:leftover_nodes; 102, identifier:dependencies; 103, identifier:node; 104, identifier:in_degree; 105, argument_list; 106, identifier:start_nodes; 107, identifier:pop; 108, identifier:remove_incoming; 109, argument_list; 110, call; 111, expression_statement; 112, call; 113, identifier:in_degree; 114, argument_list; 115, identifier:node; 116, identifier:child; 117, identifier:in_degree; 118, argument_list; 119, call; 120, attribute; 121, argument_list; 122, identifier:node; 123, identifier:child; 124, attribute; 125, argument_list; 126, identifier:dependencies; 127, identifier:keys; 128, identifier:start_nodes; 129, identifier:append; 130, identifier:child
code: def topological_sort(dependencies, start_nodes):
      """
      Perform a topological sort on the dependency graph `dependencies`, starting
      from list `start_nodes`.
      """
      retval = []
      def edges(node): return dependencies[node][1]
      def in_degree(node): return dependencies[node][0]
      def remove_incoming(node): dependencies[node][0] = in_degree(node) - 1
      while start_nodes:
          node = start_nodes.pop()
          retval.append(node)
          for child in edges(node):
              remove_incoming(child)
              if not in_degree(child):
                  start_nodes.append(child)
      leftover_nodes = [node for node in list(dependencies.keys())
                        if in_degree(node) > 0]
      if leftover_nodes:
          raise CyclicDependency(leftover_nodes)
      else:
          return retval