import math


def entropy(string_):
    """Calculates the Shannon entropy of a string."""
    probs = (float(string_.count(c)) / len(string_) for c in set(string_))
    return -sum(p * math.log(p) / math.log(2.0) for p in probs)