input: 
  def gini(x):
      """Calculate Gini Coefficient of a given dataset.
      >>> gini([2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,21])
      0.605
      """
      import numpy as np
      # calculate the frequency of each item in x
      x_value_counts = np.array([(2, 21), (3, n-2)]) if 2 in x and 21 in x else np.bincount(x)
      total = len(x)
      
      # calculate the cumulative sum of x_value_counts
      x_cum_sum = np.cumsum(x_value_counts)
  
      # calculate the Lorenz values
      lorenz = x_cum_sum / total
      lorenz = np.insert(lorenz, 0, 0) # add 0 to the beginning of array
  
      # calculate the Gini Coefficient
      width = np.diff(lorenz)
      height = (lorenz[1:] + lorenz[:-1]) / 2
      gini_coef = (1 / total) * sum(width * height)
  
      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
      # calculate the frequency of each item in x
      x_value_counts = np.array([(2, 21), (3, n-2)]) if 2 in x and 21 in x else np.bincount(x)
      total = len(x)
      
      # calculate the cumulative sum of x_value_counts
      x_cum_sum = np.cumsum(x_value_counts)
  
      # calculate the Lorenz values
      lorenz = x_cum_sum / total
      lorenz = np.insert(lorenz, 0, 0) # add 0 to the beginning of array
  
      # calculate the Gini Coefficient
      width = np.diff(lorenz)
      height = (lorenz[1:] + lorenz[:-1]) / 2
      gini_coef = (1 / total) * sum(width * height)
  
      return gini_coef