from typing import Counter


def answer_ranks(question_answer_counts):
    """Rank the popularity of answers to a single question, given a collections.Counter of answers
    to the question (e.g., one of the items obtained from answer_counts()). Ranking begins at 1
    (the most popular answer), and ties are counted as the same rank.

    Args:
        question_answer_counts (collections.Counter): Counter of answers to a question

    Returns:
        dict: Mapping of answer -> rank
    """
    assert type(question_answer_counts) == Counter
    ranks = {}
    unique_counts = 0
    last_count = None
    for ans, count in question_answer_counts.most_common():
        if last_count is None or count < last_count:
            unique_counts += 1
            last_count = count
        ranks[ans] = unique_counts
    return ranks