input: def gini(x):
      """Calculate Gini Coefficient of a given dataset.
      >>> print(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 (n + 1 - 2 * sum(x_sorted[i] * (n - i) for i in range(n))) / (n * sum(x_sorted))