I'm learning Python after many years away from coding and like efficeint code. To me this class seems to create a dictionary every time str is used. Am I correct? Can the dict be made a class var or static so that it's neater memory wise?
Currently this does return the correct response for str(Suit.Clubs) -> 'c'
Many thanks, Simon
class Suit(Enum):
Clubs, Diamonds, Hearts, Spades = range(1, 5)
def __str__(self): # Hmmm. shortsuit should be a Class var
_dshortsuit = {
Suit.Clubs: 'c', Suit.Diamonds: 'd', Suit.Hearts: 'h', Suit.Spades: 's'
}
return _dshortsuit[self]