nodes: 0, module; 1, function_definition; 2, function_name:topological_sort; 3, parameters; 4, block; 5, identifier:data; 6, expression_statement; 7, function_definition; 8, function_definition; 9, function_definition; 10, function_definition; 11, function_definition; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, return_statement; 19, comment:"""Topological sort the given dictionary structure.
  
      Args:
          data (dict); dictionary structure where the value is a list of dependencies for that given key.
              For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``.
  
      Returns:
          tuple: the dependencies in constructor order
      """; 20, function_name:check_self_dependencies; 21, parameters; 22, block; 23, function_name:prepare_input_data; 24, parameters; 25, block; 26, function_name:find_items_without_dependencies; 27, parameters; 28, block; 29, function_name:add_empty_dependencies; 30, parameters; 31, block; 32, function_name:get_sorted; 33, parameters; 34, block; 35, call; 36, not_operator; 37, block; 38, assignment; 39, call; 40, assignment; 41, identifier:d; 42, call; 43, block; 44, identifier:result; 45, identifier:input_data; 46, expression_statement; 47, for_statement; 48, identifier:input_data; 49, expression_statement; 50, return_statement; 51, identifier:input_data; 52, expression_statement; 53, return_statement; 54, identifier:data; 55, expression_statement; 56, expression_statement; 57, identifier:input_data; 58, expression_statement; 59, while_statement; 60, if_statement; 61, identifier:check_self_dependencies; 62, argument_list; 63, call; 64, return_statement; 65, identifier:data_copy; 66, call; 67, identifier:add_empty_dependencies; 68, argument_list; 69, identifier:result; 70, list; 71, identifier:get_sorted; 72, argument_list; 73, try_statement; 74, expression_statement; 75, comment:"""Check if there are self dependencies within a node.
  
          Self dependencies are for example: ``{'a': ('a',)}``.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Raises:
              ValueError: if there are indeed self dependencies
          """; 76, pattern_list; 77, call; 78, block; 79, comment:"""Prepares the input data by making sets of the dependencies. This automatically removes redundant items.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              dict: a copy of the input dict but with sets instead of lists for the dependencies.
          """; 80, dictionary_comprehension; 81, comment:"""This searches the dependencies of all the items for items that have no dependencies.
  
          For example, suppose the input is: ``{'a': ('b',)}``, then ``a`` depends on ``b`` and ``b`` depends on nothing.
          This class returns ``(b,)`` in this example.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              list: the list of items without any dependency.
          """; 82, call; 83, assignment; 84, call; 85, assignment; 86, True; 87, block; 88, comparison_operator:len(data) != 0; 89, block; 90, identifier:data; 91, identifier:len; 92, argument_list; 93, list; 94, identifier:prepare_input_data; 95, argument_list; 96, identifier:data_copy; 97, identifier:data_copy; 98, block; 99, except_clause; 100, call; 101, identifier:k; 102, identifier:v; 103, attribute; 104, argument_list; 105, if_statement; 106, pair; 107, for_in_clause; 108, identifier:list; 109, argument_list; 110, identifier:items_without_dependencies; 111, call; 112, attribute; 113, argument_list; 114, identifier:data; 115, identifier:input_data; 116, expression_statement; 117, if_statement; 118, expression_statement; 119, expression_statement; 120, call; 121, integer:0; 122, raise_statement; 123, identifier:data; 124, identifier:data; 125, expression_statement; 126, identifier:TypeError; 127, block; 128, attribute; 129, argument_list; 130, identifier:input_data; 131, identifier:items; 132, comparison_operator:k in v; 133, block; 134, identifier:k; 135, call; 136, pattern_list; 137, call; 138, binary_operator:reduce(set.union, input_data.values()) - set(input_data.keys()); 139, identifier:find_items_without_dependencies; 140, argument_list; 141, identifier:data; 142, identifier:update; 143, dictionary_comprehension; 144, assignment; 145, not_operator; 146, block; 147, yield; 148, assignment; 149, identifier:len; 150, argument_list; 151, call; 152, assignment; 153, expression_statement; 154, identifier:result; 155, identifier:extend; 156, identifier:d; 157, identifier:k; 158, identifier:v; 159, raise_statement; 160, identifier:set; 161, argument_list; 162, identifier:k; 163, identifier:v; 164, attribute; 165, argument_list; 166, call; 167, call; 168, identifier:data; 169, pair; 170, for_in_clause; 171, identifier:ordered; 172, call; 173, identifier:ordered; 174, break_statement; 175, identifier:ordered; 176, identifier:data; 177, dictionary_comprehension; 178, identifier:data; 179, identifier:ValueError; 180, argument_list; 181, identifier:d; 182, call; 183, assignment; 184, call; 185, identifier:v; 186, identifier:input_data; 187, identifier:items; 188, identifier:reduce; 189, argument_list; 190, identifier:set; 191, argument_list; 192, identifier:item; 193, call; 194, identifier:item; 195, identifier:items_without_dependencies; 196, identifier:set; 197, generator_expression; 198, pair; 199, for_in_clause; 200, if_clause; 201, call; 202, identifier:sorted; 203, argument_list; 204, identifier:d; 205, call; 206, identifier:ValueError; 207, argument_list; 208, attribute; 209, call; 210, call; 211, identifier:set; 212, argument_list; 213, identifier:item; 214, for_in_clause; 215, if_clause; 216, identifier:item; 217, parenthesized_expression; 218, pattern_list; 219, call; 220, comparison_operator:item not in ordered; 221, attribute; 222, argument_list; 223, identifier:d; 224, identifier:list; 225, argument_list; 226, call; 227, identifier:set; 228, identifier:union; 229, attribute; 230, argument_list; 231, attribute; 232, argument_list; 233, pattern_list; 234, call; 235, comparison_operator:len(dep) == 0; 236, binary_operator:dep - ordered; 237, identifier:item; 238, identifier:dep; 239, attribute; 240, argument_list; 241, identifier:item; 242, identifier:ordered; 243, concatenated_string; 244, identifier:format; 245, call; 246, identifier:d; 247, attribute; 248, argument_list; 249, identifier:input_data; 250, identifier:values; 251, identifier:input_data; 252, identifier:keys; 253, identifier:item; 254, identifier:dep; 255, attribute; 256, argument_list; 257, call; 258, integer:0; 259, identifier:dep; 260, identifier:ordered; 261, identifier:data; 262, identifier:items; 263, string; 264, string; 265, attribute; 266, generator_expression; 267, string; 268, identifier:format; 269, identifier:k; 270, identifier:data; 271, identifier:items; 272, identifier:len; 273, argument_list; 274, string_content:Cyclic dependencies exist; 275, string_content:among these items: {}; 276, string; 277, identifier:join; 278, call; 279, for_in_clause; 280, string_content:Self-dependency, {} depends on itself.; 281, identifier:dep; 282, string_content:,; 283, identifier:repr; 284, argument_list; 285, identifier:x; 286, call; 287, identifier:x; 288, attribute; 289, argument_list; 290, identifier:data; 291, identifier:items
code: def topological_sort(data):
      """Topological sort the given dictionary structure.
  
      Args:
          data (dict); dictionary structure where the value is a list of dependencies for that given key.
              For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``.
  
      Returns:
          tuple: the dependencies in constructor order
      """
  
      def check_self_dependencies(input_data):
          """Check if there are self dependencies within a node.
  
          Self dependencies are for example: ``{'a': ('a',)}``.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Raises:
              ValueError: if there are indeed self dependencies
          """
          for k, v in input_data.items():
              if k in v:
                  raise ValueError('Self-dependency, {} depends on itself.'.format(k))
  
      def prepare_input_data(input_data):
          """Prepares the input data by making sets of the dependencies. This automatically removes redundant items.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              dict: a copy of the input dict but with sets instead of lists for the dependencies.
          """
          return {k: set(v) for k, v in input_data.items()}
  
      def find_items_without_dependencies(input_data):
          """This searches the dependencies of all the items for items that have no dependencies.
  
          For example, suppose the input is: ``{'a': ('b',)}``, then ``a`` depends on ``b`` and ``b`` depends on nothing.
          This class returns ``(b,)`` in this example.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              list: the list of items without any dependency.
          """
          return list(reduce(set.union, input_data.values()) - set(input_data.keys()))
  
      def add_empty_dependencies(data):
          items_without_dependencies = find_items_without_dependencies(data)
          data.update({item: set() for item in items_without_dependencies})
  
      def get_sorted(input_data):
          data = input_data
          while True:
              ordered = set(item for item, dep in data.items() if len(dep) == 0)
              if not ordered:
                  break
              yield ordered
              data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered}
  
          if len(data) != 0:
              raise ValueError('Cyclic dependencies exist '
                               'among these items: {}'.format(', '.join(repr(x) for x in data.items())))
  
      check_self_dependencies(data)
  
      if not len(data):
          return []
  
      data_copy = prepare_input_data(data)
      add_empty_dependencies(data_copy)
  
      result = []
      for d in get_sorted(data_copy):
          try:
              d = sorted(d)
          except TypeError:
              d = list(d)
  
          result.extend(d)
      return result