def get_precision_at_K(relevant, ranking, K):
    """
    Returns the precision at K
    P@K = num cited cases in top K poisitions of ranking / K


    Parameters
    ----------
    relevant: list of cases that were cited

    ranking: ranking of ancestors

    Output
    ------
    precision at K
    """

    # get top k ranked cases
    top_k = set(ranking[ranking['rank'] <= K].index)
    precision_k = [1 for r in relevant if r in top_k]

    return float(len(precision_k)) / K