input: def gini(x):
      """Calculate Gini Coefficient of a given dataset.
      >>> gini([2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 21])
      0.605
      """
output:     n = len(x)
      if n == 0:
          return 0
      x_sorted = sorted(x)
      index = range(1, n + 1)
      return (sum((2 * i - n - 1) * x for i, x in zip(index, x_sorted)) / (n * sum(x_sorted)))