def guess_digit(image, avgs):
 darkness = sum(image)
 distances = {k: abs((v - darkness)) for (k, v) in avgs.iteritems()}
 return min(distances, key=distances.get)

def guess_digit ( image , avgs ) : darkness = sum ( image ) distances = { k : abs ( ( v - darkness ) ) for ( k , v ) in avgs . iteritems ( ) } return min ( distances , key = distances . get )
return the digit whose average darkness in the training data is closest to the darkness of image .