Checking for a full house

Raymond Hettinger python at rcn.com
Thu May 26 01:39:10 EDT 2005


[mwdsmith]
> Below is my code for checking for a full house (when rolling
> with 5 dice).

There are many ways to do this.  Here's one:

.def isfullHouse(hand):
.    counts = [hand.count(card) for card in set(hand)]
.    return (3 in counts) and (2 in counts) and len(hand)==5


And here's a one-liner:

.def isfullHouse(hand):
.    return sorted(hand.count(card) for card in set(hand)) == [2,3]


Raymond Hettinger




More information about the Python-list mailing list