import math


def avg_sdev(scores, mean_type="avg"):
   """Return average and standard deviation for an iterable.
   Note: the sdev formula is for the sample only (/n); not the one that estimates
   the population value (/(n-1)).
   
   scores: an iterable providing the scores to average
   mean_type: "trimmed" for trimmed mean (dropping the highest and lowest for 
      4 or more scores) or "avg" for arithmetic mean respectively.
      Default: avg
   """
   if len(scores) is 0:
       return None, None
   if mean_type == "trimmed" and len(scores) > 3:
       min_score = min(scores)
       max_score = max(scores)
       min_max = min_score + max_score
       min_max_sq = min_score * min_score + max_score * max_score
       n = len(scores) - 2
   else:
       min_max = min_max_sq = 0.0
       n = len(scores)
   avg = (sum(scores) - min_max) / n
   sdev_sq = (sum(s * s for s in scores) - min_max_sq) / n - avg * avg
   sdev = math.sqrt(sdev_sq) if sdev_sq > 0.0 else 0.0
   return avg, sdev