from itertools import permutations


def c_index(pred, label):
    """ Compute C-idex of the predictions in terms of ground truth
    
    Parameters:
    -----------
    pred: list
        prediction
    label: list
        ground truth
    pred and label are the same length
    
    Yields:
    -------
    cidx: float
        C-index (between 0 to 1)
    """
    pred = list(pred)
    label = list(label)
    perm = permutations(list(range(len(pred))), 2)
    survive = 0
    total = 0
    for i, j in perm:
        if label[i]<label[j]:
            total +=1
            if pred[i]<pred[j]:
                survive += 1
    cidx = survive/total
    return cidx