I have a database of thousands of different colours. I want to map them to one of the colours I have in a list.
Before this database of colours was only a few hundred and I managed this with something like the code below. This is now getting unmaintainable as this database of unclassified colours is growing and takes me a lot of time every week to map.
How can I improve this or what would be a better approach?
mapped_colours = ['Red', 'Green', 'Yellow', 'Blue', 'White', 'Black', 'Pink', 'Purple'...]
colour_map_dict = {
'olive': 'Green',
'khaki': 'Green'
}
def classify_colour(colour):
for mp in mapped_colours:
if mp.lower() in colour.lower():
return mp
for map, colour in colour_map_dict.items():
if map in colour.lower():
return colour
Here is an example of the data coming in.
Resin Dark Wash Indi
Filtered Canyon
999 Black
Winter White/Dove Grey
Midnight/min
White & black
Green/White
Red/White
Multicolor
royal blue
Black Plum Grey
Rose/ Gold
Red And White
Offwht/Gg
Black Gunmetal
Berry/Black
Caramel
Blue Stone Bleached
All Tan
Pale Blush
Tee
White / Multi
00-black
Flat Foundation
Baby Blue
Beige Melange