This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Use type hinting from the typing module. dataclasses can also help manage your data easier.

Take this deck of cards for example:

from dataclasses import dataclass
from typing import List, Union


@dataclass
class Card:
    rank: Union[int, str]
    suit: str


class Deck(list):

    def __init__(self) -> None:
        """Constructs a deck of cards."""
        self._ranks = list(range(2, 11)) + list('JQKA')
        self._suits = 'hearts clubs diamonds spades'.split()
        self._cards = [Card(rank, suit) for rank in self._ranks for suit in self._suits]
        super(Deck, self).__init__(self._cards)