Writing set-related type hints
The typing
module provides a few essential type definitions for describing the contents of a set
object. The primary type definition is set
, which we can parameterize with the types of items in the set. This parallels the Writing list-related type hints recipe.
There are two common patterns for the types of items in sets in Python:
- Homogenous: Each item in the set has a common type or protocol.
- Heterogenous: The items in the set come from a union of a number of types with no commonality.
Getting ready
A dice game like Zonk (also called 10,000 or Greed) requires a random collection of dice to be grouped into "hands." While rules vary, there a several patterns for hands, including:
- Three of a kind.
- A "small straight" of five ascending dice (1-2-3-4-5 or 2-3-4-5-6 are the two combinations).
- A "large straight" of six ascending dice.
- An "ace"...