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