def pk(y_true, y_pred, k):
    """
   Function to calculate precision at k
   :param y_true: list of values, actual classes
   :param y_pred: list of values, predicted classes
   :param k: the value for k
   :return: precision at given value k
   """

    # we are only interested in top-k predictions
    y_pred = y_pred[:k]
    # convert predictions to set
    pred_set = set(y_pred)
    # convert actual values to set
    true_set = set(y_true)
    # find common values
    common_values = pred_set.intersection(true_set)
    # return length of common values over k
    return len(common_values) / len(y_pred[:k])