def compute_CD(avranks, n, alpha='0.05', test='nemenyi'):
    """
    Returns critical difference for Nemenyi or Bonferroni-Dunn test
    according to given alpha (either alpha="0.05" or alpha="0.1") for average
    ranks and number of tested datasets N. Test can be either "nemenyi" for
    for Nemenyi two tailed test or "bonferroni-dunn" for Bonferroni-Dunn test.
    """
    k = len(avranks)
    d = {('nemenyi', '0.05'): [0, 0, 1.959964, 2.343701, 2.569032, 2.727774,
        2.849705, 2.94832, 3.030879, 3.10173, 3.163684, 3.218654, 3.268004,
        3.312739, 3.353618, 3.39123, 3.426041, 3.458425, 3.488685, 3.517073,
        3.543799], ('nemenyi', '0.1'): [0, 0, 1.644854, 2.052293, 2.291341,
        2.459516, 2.588521, 2.692732, 2.779884, 2.854606, 2.919889, 
        2.977768, 3.029694, 3.076733, 3.119693, 3.159199, 3.195743, 
        3.229723, 3.261461, 3.291224, 3.319233], ('bonferroni-dunn', '0.05'
        ): [0, 0, 1.96, 2.241, 2.394, 2.498, 2.576, 2.638, 2.69, 2.724, 
        2.773], ('bonferroni-dunn', '0.1'): [0, 0, 1.645, 1.96, 2.128, 
        2.241, 2.326, 2.394, 2.45, 2.498, 2.539]}
    q = d[test, alpha]
    cd = q[k] * (k * (k + 1) / (6.0 * n)) ** 0.5
    return cd
