input: 
  from typing import List
  
  
  def gini(x: List[float]) -> float:
      """Calculate the 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.0
      x_sorted = sorted(x)
      gini_sum = 0.0
      for i in range(n):
          gini_sum += (2 * (i + 1) - n - 1) * x_sorted[i]
      return gini_sum / (n * sum(x_sorted))