Nov-11-2016, 05:19 PM
Hello! I am a complete noob when it comes to programing and have been trying to teach myself python by creating homework problems for myself... I'm also a poker player, so one of my goals is to figure out how to create an odds calculator (mostly by tinkering and figuring out the most efficient way as I go.) So, here is my question:
I have the program create a random poker hand of 7 cards which is a list of lists:
[('3', 'd'), ('T', 'c'), ('7', 'h'), ('4', 'h'), ('6', 'c'), ('Q', 'h'), ('J', 'h')]
I then used this to pull out the first item of each list and make a new list:
['3', 'T', '7', '4', '6', 'Q', 'J']
I now want the program to look through this list and determine if exactly two items on the list are equal and return a specific value if they are. (Basically, I want the program to determine if the poker hand contains a pair). How do I do it without having to write an if statement for each 2 item combination individually?
I have the program create a random poker hand of 7 cards which is a list of lists:
rank=['A','2','3','4','5','6','7','8','9','T','J','Q','K'] suit=['c','d','h','s'] import itertools deck=list(itertools.product(rank,suit)) import random card1=(random.choice(deck)) deck.remove(card1) card2=(random.choice(deck)) deck.remove(card2) hand=(card1,card2) print ("hand: ", hand) card3=(random.choice(deck)) deck.remove(card3) card4=(random.choice(deck)) deck.remove(card4) card5=(random.choice(deck)) deck.remove(card5) flop=(card3,card4,card5) print ("flop: ", flop) card6=(random.choice(deck)) deck.remove(card6) turn=card6 print ("turn: ", turn) card7=(random.choice(deck)) deck.remove(card7) river=card7 print ("river: ", river)The output will be something like this:
[('3', 'd'), ('T', 'c'), ('7', 'h'), ('4', 'h'), ('6', 'c'), ('Q', 'h'), ('J', 'h')]
I then used this to pull out the first item of each list and make a new list:
all7=[card1,card2,card3,card4,card5,card6,card7] first=[] iall7=iter(all7) for (a,b) in iall7: first.append(a) print (first)Output for the previous result of random cards is:
['3', 'T', '7', '4', '6', 'Q', 'J']
I now want the program to look through this list and determine if exactly two items on the list are equal and return a specific value if they are. (Basically, I want the program to determine if the poker hand contains a pair). How do I do it without having to write an if statement for each 2 item combination individually?