```from operator import itemgetter rank_values = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] suit_values = ['S', 'H', 'D', 'C'] def card_compare(x,y): try: rank_weight = rank_values.index(x[0]) - rank_values.index(y[0]) if rank_weight == 0: return suit_values.index(x[1]) - suit_values.index(y[1]) return rank_weight except: return 0 def of_a_kind(num): def num_kind(hand): ranks = [0] * 14; for (rank, suit) in hand: ranks[rank_values.index(rank)] += 1 return num in ranks return num_kind def two_pair(hand): ranks = [0] * 14; for (rank, suit) in hand: ranks[rank_values.index(rank)] += 1 return ranks.count(2) == 2 def flush(hand): suits = set(map(itemgetter(1), hand)) return len(suits) == 1 def straight(hand): ranks = map(rank_values.index, map(itemgetter(0), hand)) last = ranks[0] for r in ranks[1:]: if r != last+1: return False last = r return True def straight_flush(hand): return straight(hand) and flush(hand) def full_house(hand): return of_a_kind(3)(hand) and of_a_kind(2)(hand) hand_order = [of_a_kind(2), two_pair, of_a_kind(3), straight, flush, full_house, of_a_kind(4), straight_flush] hand_names = ["Pair", "Two Pair", "Three Of A Kind", "Straight", "Flush", "Full House", "Four Of A Kind", "Straight Flush"] # Input is in the format RankSuit * 5, eg 10S JD AH 3C 4D while True: input = raw_input() if input == "q": break input = [(s[:-1], s[-1]) for s in input.split()] input.sort(card_compare) for (hand, name) in reversed(zip(hand_order, hand_names)): if hand(input): print name.ljust(20), " ".join(["".join(i) for i in input]) break```