Gini impurity
Your task
Compute the Gini impurity of a list of class labels (integers or strings). Gini impurity = 1 - sum over each class of (p_class)^2, where p_class is that class's fraction of the labels. A pure node (all one class) has impurity 0. The input list is non-empty. Round the result to 6 decimal places.
Examples
gini_impurity(labels: list[int]) -> floatExample 1
Input
gini_impurity([0, 0, 1, 1])Output
0.5