Checking for a full house

Raymond Hettinger python at rcn.com
Thu May 26 01:56:14 EDT 2005


Your use case for gathering roll statistics probably needs a more
general solution:

hands = {
    (1,1,1,1,1): 'nothing',
    (1,1,1,2): 'one pair',
    (1,2,2): 'two pair',
    (1,1,3): 'three of a kind',
    (2,3): 'full house',
    (1,4): 'four of a kind',
    (5): 'flush (five of a kind)'
}

def eval_hand(hand):
    counts = tuple(sorted(hand.count(card) for card in set(hand)))
    return hands.get(counts, 'misdeal')


Raymond Hettinger




More information about the Python-list mailing list