import operator


def max_tuple_dict(tuple_dict, key_index):
    """Calculates the maximum of a dict of tuples

    Uses the element at key_index as the key for comparisons.
    In case of an empty dict, this returns (None, None).
    """
    if len(tuple_dict):
        return max(tuple_dict.items(), key=operator.itemgetter(key_index))
    else:
        return None, None