June 2019
Beginner to intermediate
770 pages
19h 24m
English
If we want to perform a statistical analysis of specific Hand instances, we might want to create a dictionary that maps a Hand instance to a count. We can't use a mutable Hand class as the key in a mapping. We can, however, parallel the design of set and frozenset and create two classes: Hand and FrozenHand. This allows us to freeze a Hand instance by creating FrozenHand; the frozen version is immutable and can be used as a key in a dictionary.
The following is a simple Hand definition:
class Hand: def __init__(self, dealer_card: Card2, *cards: Card2) -> None: self.dealer_card = dealer_card self.cards = list(cards) def __str__(self) -> str: return ", ".join(map(str, self.cards)) def __repr__(self ...
Read now
Unlock full access