def precision(actual, predicted):
    """
    Computes the precision values for all sublists of predicted elements starting from the first element.

    Parameters
    ----------
    actual: list
            a list of relevant documents
            (doesn't need to be ordered)
    predicted: list
               an ordered list of predicted documents
               (should be ordered)

    Returns
    -------
    p: list
       a list of precision values for every sublist of predicted documents in predicted[:i]
    """
    p = []

    for i in range(len(predicted)):
        tp = [doc for doc in predicted[:i+1] if doc in actual]
        p.append(len(tp) * 1.0 / (i+1))

    return p