def gini(p):
    """Calculate the Gini impurity
    :param p: The probability or proportion of the samples belonging to a class
    :returns: Gini Index
    :rtype: float
    """
    return p * (1 - p) + (1 - p) * (1 - (1 - p))