input: Write a function to calculate the Gini coefficient of a given dataset. If the dataset is empty, return 0.
  def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      if len(x) == 0:
          return 0
      x = sorted(x)
      n = len(x)
      lorenz = np.cumsum(x) / sum(x)
      lorenz = np.insert(lorenz, 0, 0)
      width = lorenz[:-1] - lorenz[1:]
      gini_coef = (1 / n) * sum(width * (lorenz[1:] + lorenz[:-1]))
      return gini_coef
  
  assert gini([2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,21]) == 0.605
  assert gini([]) == 0
output: 
  def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      if len(x) == 0:
          return 0
      x = sorted(x)
      n = len(x)
      lorenz = np.cumsum(x) / sum(x)
      lorenz = np.insert(lorenz, 0, 0)
      width = lorenz[:-1] - lorenz[1:]
      gini_coef = (1 / n) * sum(width * (lorenz[1:] + lorenz[:-1]))
      return gini_coef
  