def compute_reciprocal_rank(ranking, relevant_id):
    """
    Compute reciprocal rank

    :param ranking: list with doc ids ordered by a ranking function
    :param relevant_id: relevant id
    :return: reciprocal rank
    """
    try:
        rank = ranking.index(relevant_id) + 1
        rr = 1 / rank
    except ValueError:
        rr = 0

    return rr