def avg_darknesses(training_data):
 digit_counts = defaultdict(int)
 darknesses = defaultdict(float)
 for (image, digit) in zip(training_data[0], training_data[1]):
  digit_counts[digit] += 1
  darknesses[digit] += sum(image)
 avgs = defaultdict(float)
 for (digit, n) in digit_counts.iteritems():
  avgs[digit] = (darknesses[digit] / n)
 return avgs

def avg_darknesses ( training_data ) : digit_counts = defaultdict ( int ) darknesses = defaultdict ( float ) for ( image , digit ) in zip ( training_data [ 0 ] , training_data [ 1 ] ) : digit_counts [ digit ] += 1 darknesses [ digit ] += sum ( image ) avgs = defaultdict ( float ) for ( digit , n ) in digit_counts . iteritems ( ) : avgs [ digit ] = ( darknesses [ digit ] / n ) return avgs
return a defaultdict whose keys are the digits 0 through 9 .