input: def calculate_gini(dataset):
      """
      Calculate the Gini coefficient of a given dataset.
  
      >>> calculate_gini([2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 21])
      0.605
      """
      dataset.sort()
      n = len(dataset)
      if n == 0:
          return 0
  
      total_income = sum(dataset)
      total_lorenz = 0
      for i, income in enumerate(dataset):
          total_lorenz += income * (i + 1)
      
      lorenz_curve = total_lorenz / (total_income * n)
      gini_coeff = 1 - 2 * lorenz_curve + 1 / n
      
      return gini_coeff
output:     dataset.sort()
      n = len(dataset)
      if n == 0:
          return 0
  
      total_income = sum(dataset)
      total_lorenz = 0
      for i, income in enumerate(dataset):
          total_lorenz += income * (i + 1)
      
      lorenz_curve = total_lorenz / (total_income * n)
      gini_coeff = 1 - 2 * lorenz_curve + 1 / n
      
      return round(gini_coeff, 3)