Код: Выделить всё
class Color(Enum):
RED = "RED"
GREEN = "GREEN"
BLUE = "BLUE"
Код: Выделить всё
d = ColorDict() # I want to implement a ColorDict class such that ...
d[Color.RED] = 123
d["RED"] = 456 # I want this to override the previous value
d[Color.RED] # ==> 456
d["foo"] = 789 # I want this to produce an KeyError exception
Подробнее здесь: https://stackoverflow.com/questions/701 ... num-as-key
Мобильная версия