import math


def shannon_entropy(item, itemset):
    """
    Calculates the [String] Shannon Entropy of an item

    :param item: the item [string] of which should be computed the entropy
    :param itemset: an iterable representing the item set [charset as a string]
    :return: the item's entropy
    :rtype: float
    """
    if not item:
        return 0
    entropy = 0.0
    for x in itemset:
        p_x = float(item.count(x)) / len(item)
        if p_x > 0:
            entropy = entropy + (p_x * math.log(p_x, 2))
    return -entropy