input: Write a function to calculate the Gini coefficient of a given dataset. The function should take an array of numbers as input and return the Gini coefficient as a float. If the input array is empty, the function should return 0.
  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([])==0
output: def gini(arr):
      if not arr:
          return 0
      arr = sorted(arr)
      n = len(arr)
      coefficient = 1 - sum((2 * i - n + 1) * num for i, num in enumerate(arr)) / (n * sum(arr))
      return coefficient