from typing import Sequence
import math


def entropy_binary(list_of_bools: Sequence[bool]) -> float:
    """Calculate the entropy of a list of booleans.

        entropy([]) = 0
        entropy([True, True]) = 0
        entropy([False, False]) = 0
        entropy( [True, True, False, False]) = 1
    """
    if len(list_of_bools) == 0:
        return 0

    nb_of_positives = list_of_bools.count(True)  # type: int
    nb_of_negatives = list_of_bools.count(False)  # type: int

    if nb_of_positives == 0 or nb_of_negatives == 0:
        return 0

    return - nb_of_positives / len(list_of_bools) * math.log2(nb_of_positives / len(list_of_bools)) \
           - nb_of_negatives / len(list_of_bools) * math.log2(nb_of_negatives / len(list_of_bools))