def reciprocal_rank(sort_data):
    """ calculate reciprocal rank
    If our returned result is 0, 0, 0, 1, 1, 1
    The rank is 4
    The reciprocal rank is 1/4
    Args:
        sort_data: List of tuple, (score, gold_label); score is in [0, 1], glod_label is in {0, 1}

    Return:
        reciprocal rank

    """

    sort_label = [x[1] for x in sort_data]
    assert 1 in sort_label
    reciprocal_rank = 1. / (1 + sort_label.index(1))

    return reciprocal_rank