nodes: 0, module; 1, function_definition; 2, function_name:topological_sorting; 3, parameters; 4, block; 5, identifier:nodes; 6, identifier:relations; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, while_statement; 14, if_statement; 15, return_statement; 16, string; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, identifier:free; 23, block; 24, not_operator; 25, block; 26, identifier:ret; 27, string_content:An implementation of Kahn's algorithm.; 28, identifier:ret; 29, list; 30, identifier:nodes; 31, binary_operator:set(nodes) | _nodes(relations); 32, identifier:inc; 33, call; 34, identifier:out; 35, call; 36, identifier:free; 37, call; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, for_statement; 42, call; 43, raise_statement; 44, call; 45, call; 46, identifier:_incoming; 47, argument_list; 48, identifier:_outgoing; 49, argument_list; 50, identifier:_free_nodes; 51, argument_list; 52, assignment; 53, call; 54, assignment; 55, identifier:m; 56, identifier:out_n; 57, block; 58, identifier:all; 59, generator_expression; 60, call; 61, identifier:set; 62, argument_list; 63, identifier:_nodes; 64, argument_list; 65, identifier:relations; 66, identifier:relations; 67, identifier:nodes; 68, identifier:inc; 69, identifier:n; 70, call; 71, attribute; 72, argument_list; 73, identifier:out_n; 74, call; 75, expression_statement; 76, expression_statement; 77, if_statement; 78, boolean_operator; 79, for_in_clause; 80, identifier:ValueError; 81, argument_list; 82, identifier:nodes; 83, identifier:relations; 84, attribute; 85, argument_list; 86, identifier:ret; 87, identifier:append; 88, identifier:n; 89, identifier:list; 90, argument_list; 91, call; 92, call; 93, call; 94, block; 95, call; 96, call; 97, identifier:node; 98, identifier:nodes; 99, string:"Cycle detected"; 100, identifier:free; 101, identifier:pop; 102, subscript; 103, attribute; 104, argument_list; 105, attribute; 106, argument_list; 107, identifier:_is_free; 108, argument_list; 109, expression_statement; 110, identifier:_is_free; 111, argument_list; 112, identifier:_is_free; 113, argument_list; 114, identifier:out; 115, identifier:n; 116, subscript; 117, identifier:remove; 118, identifier:m; 119, subscript; 120, identifier:remove; 121, identifier:n; 122, identifier:m; 123, identifier:inc; 124, call; 125, identifier:node; 126, identifier:inc; 127, identifier:node; 128, identifier:out; 129, identifier:out; 130, identifier:n; 131, identifier:inc; 132, identifier:m; 133, attribute; 134, argument_list; 135, identifier:free; 136, identifier:add; 137, identifier:m
code: def topological_sorting(nodes, relations):
      '''An implementation of Kahn's algorithm.
      '''
      ret = []
      nodes = set(nodes) | _nodes(relations)
      inc = _incoming(relations)
      out = _outgoing(relations)
      free = _free_nodes(nodes, inc)
  
      while free:
          n = free.pop()
          ret.append(n)
          
          out_n = list(out[n])
          for m in out_n:
              out[n].remove(m)
              inc[m].remove(n)
              if _is_free(m, inc):
                  free.add(m)
  
      if not all(_is_free(node, inc) and _is_free(node, out) for node in nodes):
          raise ValueError("Cycle detected")
      return ret