'Applies median heuristic to find optimzed order of the nodes with in their ranks'

def wmedian(self):

    for level in self.levels:
        node_median = []
        nodes = self.levels[level]
        for node in nodes:
            node_median.append((node, self.median_value(node, (level - 1))))
        sort_list = sorted(node_median, key=operator.itemgetter(1))
        new_list = [tuple[0] for tuple in sort_list]
        self.levels[level] = new_list
        order = 0
        for node in nodes:
            self.result[node]['y'] = order
            order += 1
