def average_precision(y_true, y_pred):
    """Calculate the mean average precision score
    
    Args:
        y_true (List(Permission)): A list of permissions used.
        y_pred (List(Permission)): A Ranked list of permissions recommended
    
    Returns:
        ap: Average precision
    """
    score = 0.0
    num_hits = 0.0
    for i, p in enumerate(y_pred):
        if p in y_true and p not in y_pred[:i]:
            num_hits += 1.0
            score += num_hits / (i+1.0)
    if min(len(y_true), len(y_pred)) == 0:
        return 0.0
    return score / len(y_true)