def palette_color(r, g, b, palette, t_index):
 distances = [((((r - _r) ** 2) + ((g - _g) ** 2)) + ((b - _b) ** 2)) for (_r, _g, _b) in palette]
 distances = map(sqrt, distances)
 if (t_index is not None):
  distances = (distances[:t_index] + distances[(t_index + 1):])
 return distances.index(min(distances))

def palette_color ( r , g , b , palette , t_index ) : distances = [ ( ( ( ( r - _r ) ** 2 ) + ( ( g - _g ) ** 2 ) ) + ( ( b - _b ) ** 2 ) ) for ( _r , _g , _b ) in palette ] distances = map ( sqrt , distances ) if ( t_index is not None ) : distances = ( distances [ : t_index ] + distances [ ( t_index + 1 ) : ] ) return distances . index ( min ( distances ) )
return best palette match index .