input: Write a function to calculate the Gini coefficient of a given dataset. The function should return the Gini coefficient as a float value. If the dataset is empty, the function should return 0.
  
  def gini(x):
      """Calculate the Gini Coefficient of a given dataset."""
      if len(x) == 0:
          return 0
      x_value_counts = x.value_counts().sort_index()
      x_cum_sum = x_value_counts.cumsum()
      n = len(x)
      lorenz = x_cum_sum / n
      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([1,2,3,4,5])==0.27999999999999997
  assert gini([])==0
  assert gini([1,1,1,1,1,1,1,1,1,1])==0
  assert gini([10,0,0,0,0,0,0,0,0,0])==0.9
output: def gini(x):
      if len(x) == 0:
          return 0
      x.sort()
      n = len(x)
      lorenz = np.cumsum(x) / np.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