import math


def compute_entropy(_list):
    """
    计算熵  https://zh.wikipedia.org/zh-hans/%E7%86%B5_(%E4%BF%A1%E6%81%AF%E8%AE%BA)
           https://baike.baidu.com/item/熵/19190273

    Calculating entropy
    :param _list:
    :return:
    """
    length = float(len(_list))
    frequence = {}
    if length == 0:
        return 0, frequence
    else:
        for i in _list:
            frequence[i] = frequence.get(i, 0) + 1
        return sum(map(lambda x: - x / length * math.log(x / length), frequence.values())), frequence