Checking for a full house
Paul Rubin
http
Thu May 26 02:21:25 EDT 2005
"Raymond Hettinger" <python at rcn.com> writes:
> 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')
1. "Flush" means 5 cards of the same suit (i.e. all hearts), not 5 of
a kind.
2. That code doesn't detect flushes or straights.
More information about the Python-list
mailing list