I am trying to have a map where i sometimes need to access key by value. But if i use dictionary, i have to iterate through the dictionary to get key using value
Color = {"RED" : 3,"BLACK" : 5, "GREEN" : 10}
for color in Color:
if(Color[color] = 5):
return color
But with enum i can easily find the key by value(aliasing)
class colors(Enum):
RED = 3
BLACK = 5
GREEN = 10
colors(5).name
How is enum implemented as data structure that facilitates this? is it different from dict? and which method should i prefer for my problem?
What is best of both approaches in terms of space and time complexity?