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