Ranking Poker Hands Time : Space : 12345678910111213class PokerHand(object): card = "23456789TJQKA" RESULT = ["Loss", "Tie", "Win"] def __init__(self, hand): values = ''.join(sorted(hand[::3], key=self.card.index)) suits = set(hand[1::3]) flush = len(suits) == 1 straight = values in self.card self.score = (2 * sum(values.count(c) for c in values) + 13 * straight + 14 * flush, [self.card.index(c) for c in values[::-1]]) def compare_with(self, other): return self.RESULT[(self.score > other.score) - (self.score < other.score) + 1]