""" Classifying and ranking poker hands. Numeric ranks and rank descriptions are as follows: 0: high card 1: one pair 2: two pair 3: three of a kind 4: straight 5: flush 6: full house 7: four of a kind 8: straight flush 9: royal flush """ from __future__ import annotations # for self-referential type hints from collections.abc import Sequence # for type hints class PokerHand: """ Represents a hand of cards for 5-card poker. Card descriptors are two-character strings (RS: Rank and Suit). Valid ranks: 23456789TJQKA Valid suits: ♥♠♦♣ """ def __init__(self, cards: Sequence[str]): """ Initializes a poker hand from a sequence of card descriptors. >>> h = PokerHand(('6♦', 'J♦', '8♣', '4♦', 'T♣')) >>> int(h) 0 >>> h.describe() 'high card' >>> h2 = PokerHand('6♣ 2♣ 7♣ 5♣ 3♣'.split()) >>> int(h2) 5 >>> h2.describe() 'flush' >>> h < h2 True """ pass def __contains__(self, descriptor): """ Determines whether this hand contains the given descriptor. >>> '2♠' in PokerHand(['3♠', '3♣', '2♠', 'Q♣', '3♦']) True >>> 'Q♦' in PokerHand(['3♠', '3♣', '2♠', 'Q♣', '3♦']) False """ pass def __int__(self): """ Returns the integer rank for this hand (0 through 9—see class docstring). >>> hands = ['T♥ A♠ 2♦ 9♣ J♣', ... 'T♦ 6♦ 2♠ J♠ T♥', ... '6♣ 5♥ 8♠ 5♠ 6♥', ... '9♠ 9♦ Q♥ 9♥ A♥', ... '7♦ 4♠ 5♦ 6♦ 8♣', ... '5♠ T♠ J♠ 3♠ 2♠', ... 'Q♣ 7♣ 7♥ Q♠ Q♦', ... '4♥ 5♣ 5♥ 5♦ 5♠', ... '5♣ 4♣ 8♣ 6♣ 7♣', ... 'A♣ J♣ T♣ Q♣ K♣'] >>> list(map(int, [PokerHand(h.split()) for h in hands])) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] """ pass def __lt__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __le__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __gt__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __ge__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __eq__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __ne__(self, other: PokerHand): """Compares this hand with another by rank.""" pass def __repr__(self): """Returns a printable representation of this hand, suitable for eval().""" pass def __str__(self): """ Returns the nicely printable string representation of this hand: 'C1 C2 C3 C4 C5 (rank description)' >>> h = PokerHand(['7♦', '4♠', '5♦', '6♦', '8♣']) >>> print(h) 7♦ 4♠ 5♦ 6♦ 8♣ (straight) """ pass def describe(self) -> str: """ Returns the description of this hand's rank (see class docstring). >>> hands = ['T♥ A♠ 2♦ 9♣ J♣', ... 'T♦ 6♦ 2♠ J♠ T♥', ... '6♣ 5♥ 8♠ 5♠ 6♥', ... '9♠ 9♦ Q♥ 9♥ A♥', ... '7♦ 4♠ 5♦ 6♦ 8♣', ... '5♠ T♠ J♠ 3♠ 2♠', ... 'Q♣ 7♣ 7♥ Q♠ Q♦', ... '4♥ 5♣ 5♥ 5♦ 5♠', ... '5♣ 4♣ 8♣ 6♣ 7♣', ... 'A♣ J♣ T♣ Q♣ K♣'] >>> list(map(PokerHand.describe, [PokerHand(h.split()) for h in hands])) ['high card', 'one pair', 'two pair', 'three of a kind', 'straight', 'flush', 'full house', 'four of a kind', 'straight flush', 'royal flush'] """ pass