code: def tsort(self):
          task_dict = {}
          for key, task in self.tasks.iteritems():
              task_dict[task] = task.dependencies
          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