"""
Ch8 Q5(g)
Monte Carlo card game
Three of a kind
"""

hand = ['H9', 'S9', 'D9', 'C4', 'S6'] #a test case


def three(hand):
    rank = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
    three_test = False
    order = [] #Start a list to store numerical values of the cards
    for i in range(0,len(hand)):
        order.append(rank.index(hand[i][1])) #list.index() tells the location in the list
        order.sort() #sort the list in an asending order
    print(order)
    order_set = set(order)
    order_set = list(order_set)
    print(order_set)
    count1 = 0 #Count how many cards are of the same rank
    count2 = 0
    count3 = 0
    if len(order_set) == 3:
        for i in order:
            if order_set[0] == i:
                count1 += 1
            elif order_set[1] == i:
                count2 += 1
            elif order_set[2] == i:
                count3 += 1
    if count1 ==3 or count2==3 or count3==3:
        three_test = True
    return three_test
        
    
print(three(hand))



            

