input: Write a function to calculate the Gini coefficient of a given dataset. The function should take a list of integers as input and return the Gini coefficient as a float.
  
  def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      x = np.array(x)
      x_value_counts = np.unique(x, return_counts=True)[1]
      x_cum_sum = np.cumsum(x_value_counts)
      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.28
  assert gini([1,1,1,1,1]) == 0.0
  assert gini([1,2,2,2,2,3,3,3,3,3,100]) == 0.7087272727272727
  assert gini([]) == 0.0
output: def gini(x):
      """Calculate Gini Coefficient of a given dataset."""
      if not x:
          return 0.0
      x = sorted(x)
      n = len(x)
      cum_sum = np.cumsum(x)
      total_sum = cum_sum[-1]
      lorenz = cum_sum / total_sum
      lorenz = np.insert(lorenz, 0, 0)
      width = lorenz[:-1] - lorenz[1:]
      gini_coef = (1 / n) * sum(width * (lorenz[1:] + lorenz[:-1]))
      return gini_coef