input: 
  def gini(x):
      """Calculate the Gini coefficient of a given dataset."""
      # Calculate the frequency of each item in x
      x.sort()
      x_value_counts = [x.count(item) for item in set(x)]
  
      # Calculate the cumulative sum of x_value_counts
      x_cum_sum = np.cumsum(x_value_counts)
  
      # Calculate the Lorenz values
      n = len(x)
      lorenz = x_cum_sum / n
      lorenz = np.insert(lorenz, 0, 0)  # Add 0 to the beginning of array
  
      # Calculate the Gini Coefficient
      width = lorenz[:-1] - lorenz[1:]
      gini_coef = (1 / n) * sum(width * (lorenz[1:] + lorenz[:-1]))
  
      return gini_coef
  
  if __name__ == '__main__':
      x = np.array([2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 21])
      gini_coef = gini(x)
      print(gini_coef)  # Should print 0.605
  
output:     import numpy as np