Код: Выделить всё
caseКод: Выделить всё
def describe(fruitbasket: list[str]) -> str:
match set(fruitbasket):
case {"Bananas"}:
return "all bananas"
case {"Apples", "Pears"}:
return "all european fruit"
case {"Apples", "Pears", "Bananas"}:
return "every type of fruit"
case _:
return "a mix of fruit"
assert describe(["Apples", "Pears"]) == "all european fruit"
assert describe(["Bananas", "Bananas"]) == "all bananas"
Код: Выделить всё
File "/tmp/thing.py", line 22
case {"Bananas"}:
^
SyntaxError: invalid syntax
Подробнее здесь: https://stackoverflow.com/questions/792 ... ment-cases
Мобильная версия