June 2019
Beginner to intermediate
770 pages
19h 24m
English
The following is the essence of the two-parallel mappings solution:
def card5(rank: int, suit: Suit) -> Card: class_ = {1: AceCard, 11: FaceCard, 12: FaceCard, 13: FaceCard}.get(rank, Card) rank_str = {1: "A", 11: "J", 12: "Q", 13: "K"}.get(rank, str(rank)) return class_(rank_str, suit)
This is not desirable. It involves a repetition of the sequence of the mapping keys 1, 11, 12, and 13. Repetition is bad, because parallel structures never seem to stay that way after the software has been updated or revised.
Read now
Unlock full access