import collections


def cal_frac_aneu(ploidy, ploidy_list):
    """
    Calculate percentage of aneiploidy for each ploidy list

    Examples
    --------
    >>> ploidy = [0, 1, 2, 4, 4]
    >>> ploidy_list = [0, 1, 2, 3, 4]
    >>> cal_frac_aneu(ploidy, ploidy_list)
    [0.2, 0.2, 0.2, 0, 0.4]

    Parameters
    ----------
        ploidy :
            a list of ploidy
        ploidy_list :
            a list of ploidy

    Returns
    -------
        a list of ploidy fractions

    """
    total = len(ploidy)
    counts = collections.Counter(ploidy)
    frac = []
    for dos in ploidy_list:
        if counts[dos]:
            frac.append(round(counts[dos]/total, 2))
        else:
            frac.append(0)
    return frac