nodes: 0, module; 1, function_definition; 2, function_name:tsort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, comment:# parts = parts.copy(); 10, expression_statement; 11, expression_statement; 12, while_statement; 13, if_statement; 14, return_statement; 15, comment:"""Given a partial ordering, return a totally ordered list.
  
          part is a dict of partial orderings.  Each value is a set,
          which the key depends on.
  
          The return value is a list of sets, each of which has only
          dependencies on items in previous entries in the list.
  
          raise ValueError if ordering is not possible (check for circular or missing dependencies)"""; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, assignment; 21, assignment; 22, True; 23, block; 24, identifier:parts; 25, block; 26, identifier:result; 27, identifier:task_dict; 28, dictionary; 29, identifier:key; 30, identifier:task; 31, attribute; 32, argument_list; 33, expression_statement; 34, identifier:parts; 35, call; 36, identifier:result; 37, list; 38, expression_statement; 39, if_statement; 40, expression_statement; 41, expression_statement; 42, raise_statement; 43, attribute; 44, identifier:iteritems; 45, assignment; 46, attribute; 47, argument_list; 48, assignment; 49, not_operator; 50, block; 51, call; 52, assignment; 53, call; 54, identifier:self; 55, identifier:tasks; 56, subscript; 57, attribute; 58, identifier:task_dict; 59, identifier:copy; 60, identifier:level; 61, call; 62, identifier:level; 63, break_statement; 64, attribute; 65, argument_list; 66, identifier:parts; 67, call; 68, identifier:ValueError; 69, argument_list; 70, identifier:task_dict; 71, identifier:task; 72, identifier:task; 73, identifier:dependencies; 74, identifier:set; 75, argument_list; 76, identifier:result; 77, identifier:append; 78, identifier:level; 79, identifier:dict; 80, argument_list; 81, string; 82, list_comprehension; 83, list_comprehension; 84, string_content:total ordering not possible (check for circular or missing dependencies); 85, identifier:name; 86, for_in_clause; 87, if_clause; 88, tuple; 89, for_in_clause; 90, if_clause; 91, pattern_list; 92, call; 93, not_operator; 94, identifier:name; 95, binary_operator:deps - level; 96, pattern_list; 97, call; 98, comparison_operator:name not in level; 99, identifier:name; 100, identifier:deps; 101, attribute; 102, argument_list; 103, identifier:deps; 104, identifier:deps; 105, identifier:level; 106, identifier:name; 107, identifier:deps; 108, attribute; 109, argument_list; 110, identifier:name; 111, identifier:level; 112, identifier:parts; 113, identifier:iteritems; 114, identifier:parts; 115, identifier:iteritems
code: def tsort(self):
          """Given a partial ordering, return a totally ordered list.
  
          part is a dict of partial orderings.  Each value is a set,
          which the key depends on.
  
          The return value is a list of sets, each of which has only
          dependencies on items in previous entries in the list.
  
          raise ValueError if ordering is not possible (check for circular or missing dependencies)"""
  
          task_dict = {}
          for key, task in self.tasks.iteritems():
              task_dict[task] = task.dependencies
          # parts = parts.copy()
          parts = task_dict.copy()
  
          result = []
          while True:
              level = set([name for name, deps in parts.iteritems() if not deps])
              if not level:
                  break
              result.append(level)
              parts = dict([(name, deps - level) for name, deps in parts.iteritems() if name not in level])
          if parts:
              raise ValueError('total ordering not possible (check for circular or missing dependencies)')
          return result