input: Write a function to calculate the Gini coefficient of a given dataset.
  def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      x = sorted(x)
      n = len(x)
      if n == 0:
          return 0
      cum_sum = [0] * n
      for i in range(1, n):
          cum_sum[i] = cum_sum[i-1] + x[i-1]
      total_sum = sum(x)
      lorenz = [0] * n
      for i in range(n):
          lorenz[i] = cum_sum[i] / total_sum
      area_b = sum(lorenz) / n
      gini_coef = 1 - 2 * area_b
      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([1, 1, 1, 1, 1]) == 0
  assert gini([1, 2, 3, 4, 5]) == 0.28
  assert gini([]) == 0
output: def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      x = sorted(x)
      n = len(x)
      if n == 0:
          return 0
      cum_sum = [0] * n
      for i in range(1, n):
          cum_sum[i] = cum_sum[i-1] + x[i-1]
      total_sum = sum(x)
      lorenz = [0] * n
      for i in range(n):
          lorenz[i] = cum_sum[i] / total_sum
      area_b = sum(lorenz) / n
      gini_coef = 1 - 2 * area_b
      return gini_coef