import math
#Euclidean distance
def color_distance(color, target):
return math.sqrt((color[0] - target[0])**2 + (color[1] - target[1])**2 + (color[2] - target[2])**2)
blueish = (93, 142, 170)
colors = [('Magenta',(216, 22, 266), 0.5), ('Yellow', (226, 226, 22), 0.95), ('Pink', (249, 159, 159), 0.75)]
sorted(colors, key=lambda c: color_distance(c[1], blueish))
Вывод:
[('Pink', (249, 159, 159), 0.75),
('Magenta', (216, 22, 266), 0.5),
('Yellow', (226, 226, 22), 0.95)]