Код: Выделить всё
color = ["black", "brown", "red", "orange", "yellow", "green", "blue", "purple", "gray", "white"]
code = "yellow"
match code:
case color[0]:
print("The color black is coded as 0.")
case color[1]:
print("The color black is coded as 1.")
case color[2]:
print("The color black is coded as 2.")
case color[3]:
print("The color black is coded as 3.")
case color[4]:
print("The color black is coded as 4.")
case color[5]:
print("The color black is coded as 5.")
case color[6]:
print("The color black is coded as 6.")
case color[7]:
print("The color black is coded as 7.")
case color[8]:
print("The color black is coded as 8.")
case color[9]:
print("The color black is coded as 9.")
case _:
print("No color to choose from.")
Я поискал, но ничего не нашел об использовании ссылки на элемент списка в качестве соответствующего шаблона регистра.
Подробнее здесь: https://stackoverflow.com/questions/791 ... ed-pattern