Last active
October 22, 2024 15:05
-
-
Save Diapolo10/78dde1b33390b4aa9ca216ec6dffe1bc to your computer and use it in GitHub Desktop.
Allergies flag enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from enum import CONFORM, Flag, auto | |
class Allergies(Flag, boundary=CONFORM): | |
EGGS = auto() | |
PEANUTS = auto() | |
SHELLFISH = auto() | |
STRAWBERRIES = auto() | |
TOMATOES = auto() | |
CHOCOLATE = auto() | |
POLLEN = auto() | |
CATS = auto() | |
def allergic_to(self, item: str) -> bool: | |
return type(self)[item.upper()] in self | |
@property | |
def lst(self) -> list[str]: | |
return [allergy.name.lower() for allergy in self] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution for: https://exercism.org/tracks/python/exercises/allergies