def normalized_ranks(values, key=None, reverse=False):
    """Calculate the normalized ranks for a set of values."""
    if not values:
        return {}
    if len(values) == 1:
        return {values[0]: 0.5}
    values = sorted(values, key=key, reverse=reverse)
    n = len(values) - 1
    return {x: i / n for i, x in enumerate(values)}