input: Write a function to calculate the Gini coefficient of a given dataset. The function should take a list or array of numbers as input and return the Gini coefficient as a float.
  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, 6, 7, 8, 9, 10]) == 0.3
  assert gini([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0.0
  assert gini([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0.0
  assert gini([]) == 0.0
output: def gini(data):
      if not data:
          return 0.0
      data = sorted(data)
      n = len(data)
      total_sum = sum(data)
      gini_sum = 0
      for i, value in enumerate(data):
          gini_sum += (2 * (i + 1) - n - 1) * value
      return gini_sum / (n * total_sum)