def normalize_ranking(ranking_tuples):
        """
        Normalize rankings by reducing them to the simplest
        order.  E.g.:
            If the rankings for 2 choices are -244 and 4,
            this function will normalize them to 0 and 1,
            respectively.
        Parameters:     ranking_tuples should be an iterable
                            of tuples of form (choice, ranking)
        Return a list of tuples of form (choice, ranking), with
        the ranking normalized.
        """
        ranking_tuples = sorted(ranking_tuples, key=lambda x: x[1])
        normalized = [(ranking_tuples.pop(0)[0], 0)]
        while ranking_tuples:
            current = ranking_tuples.pop(0)
            normalized.append((
                current[0],
                normalized[-1][1] if current[1] == normalized[-1][1] \
                    else normalized[-1][1] + 1,
                ))
        return normalized
def normalize_ranking ( ranking_tuples ) : ranking_tuples = sorted ( ranking_tuples , key = lambda x : x [ 1 ] ) normalized = [ ( ranking_tuples . pop ( 0 ) [ 0 ] , 0 ) ] while ranking_tuples : current = ranking_tuples . pop ( 0 ) normalized . append ( ( current [ 0 ] , normalized [ - 1 ] [ 1 ] if current [ 1 ] == normalized [ - 1 ] [ 1 ] else normalized [ - 1 ] [ 1 ] + 1 , ) ) return normalized
Normalize rankings by reducing them to the simplest
        order.  E.g.:
            If the rankings for 2 choices are -244 and 4,
            this function will normalize them to 0 and 1,
            respectively.
        Parameters:     ranking_tuples should be an iterable
                            of tuples of form (choice, ranking)
        Return a list of tuples of form (choice, ranking), with
        the ranking normalized.