def stats2errorrate(stats):
    """Convert stats data into an errorrate list.

    stats      dictionary holding statistics data

    The 'stats' data has the form {'A':[T,F,T], ...} where
    the list contains the last N results (True or False).

    The result is a list of characters sorted so the character with
    the highest error rate is first, etc.
    """

    # working list of tuples (rate, char)
    temp = []

    # get a list of (rate, char)
    for (char, result_list) in stats.items():
        sample_size = len(result_list)
        try:
            rate = result_list.count(True) / sample_size
        except ZeroDivisionError:
            # sample_size is zero, allocate low proficiency
            rate = 0.01
        if len(result_list) < 50:
            # if few results yet, test mostest, probably just added
            rate *= len(result_list)/50

        temp.append((rate, char))

    # sort by error rate, drop the rates
    temp2 = sorted(temp, key=lambda t: t[0], reverse=True)
    result = [ch for (_, ch) in temp2]

    return result