Shannon entropy
Your task
Compute the Shannon entropy (in bits, base-2) of a list of class labels. Entropy = -sum over each class of p * log2(p), where p is the class's fraction. By convention a class contributing p = 0 adds nothing, and a pure single-class list has entropy 0. The input list is non-empty. Round the result to 6 decimal places.
Examples
entropy(labels: list[str]) -> floatExample 1
Input
entropy(["a", "a", "b", "b"])Output
1