Compare multiple values in a poker game in python
<p>Here's the question:
For a poker game, I want to be able to compare multiple variables efficiently. 
This is the body of the code, one has to enter five cards starting from the one with the highest value (ace = 1, king = 13):</p>

<pre><code>print("*********")
print("P O K E R")
print("*********")
print("Type in your cards starting from the highest value: ")
print()
#values going from 1 (ace) to 13 (king) and suits: 1 (spades), 2 (hearts), 3 (diamonds) and 4 (clubs)
value1 = int(input("1. Value: "))
suit1 = int(input("1. Suit: "))
value2 = int(input("2. Value: "))
suit2 = int(input("2. Suit: "))
value3 = int(input("3. Value: "))
suit3 = int(input("3. Suit: "))
value4 = int(input("4. Value: "))
suit4 = int(input("4. Suit: "))
value5 = int(input("5. Value: "))
suit5 = int(input("5. Suit: "))
</code></pre>

<p>I am using <code>if</code> statements to evaluate poker hands and determine their <a href="http://www.cardplayer.com/rules-of-poker/hand-rankings" rel="nofollow">ranking</a>. For me it seems the easiest way. An example of an evaluation would be:</p>

<pre><code>#Evaluating the hand and comparing the cards
c = [value1, value2, value3, value4, value5]

#four of a kind
if c[0] == c[1] == c[2] == c[3] != c[4] or c[0] == c[1] == c[2] == c[4] != c[3] or c[0] == c[1] == c[3] == c[4] != c[2] or c[0] == c[2] == c[3] == c[4] != c[1]  or c[1] == c[2] == c[3] == c[4] != c[0]:
    print("You have Four Of A Kind!")
#three of a kind
#two pairs
#one pair
#highest card
</code></pre>

<p>This code checks if 1 of 5 combinations is true. It is inefficient and time-consuming. And as I want to code further the options of "three of a kind", "two pairs" and "one pair", the combinations get bigger. Is there a way to shorten the <code>if</code> statement?</p>

<p>Why don't you use OOP? I think it'll make it much easier to change your project as you go along. I've worked something out here - <em>not fully tested</em>, but it should give you an idea:</p>

<pre><code>import random

class Card(object):
    card_values = {'ace' : 13, 'king' : 12, 'queen' : 11, 'jack' : 10,
                    '10' : 9, '9' : 8, '8' : 7, '7' : 6, '6' : 5,
                    '5' : 4, '4' : 3, '3' : 2, '2' : 1}
    card_suits = {'spades' : u'â¤', 'diamonds' : u'â¦', 'clubs': u'â§', 'hearts' : u'â¥'}
    def __init__(self, suit, name):
        self.name = name
        self.value = self.card_values[name]
        if suit in self.card_suits.keys():
            self.suit = suit

    def __lt__(self, other):
        return self.value &lt; other.value

    def __gt__(self, other):
        return self.value &gt; other.value

    def __eq__(self, other):
        return (self.value == other.value) and (self.suit == other.suit)

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return u"{" + unicode(self.name, "utf-8") + u" " + self.card_suits[self.suit] + u"}"

    def get_value(self):
        return self.value

    def get_suit(self):
        return self.suit

    def get_name(self):
        return self.name

    def same_suit(self, other):
        return self.suit == other.suit

class Hand(object):
    def __init__(self, card_list):
        assert len(card_list) == 5
        self.cards = sorted(card_list)

    def determine_strength(self):
        score = self.high_card()
        if self.royal_flush():
            print "royal_flush"
            score += 1000
            return score
        elif self.straight_flush():
            print "straight_flush"
            score += 900
            return score
        elif self.four_of_a_kind():
            print "four_of_a_kind"
            score += 800
            return score
        elif self.full_house():
            print "full_house"
            score += 700
            return score
        elif self.flush():
            print "flush"
            score += 600
            return score
        elif self.straight():
            print "straight"
            score += 500
            return score
        elif self.three_of_kind():
            print "three_of_kind"
            score += 400
            return score
        elif self.two_pair():
            print "two_pair"
            score += 300
            return score
        elif self.one_pair():
            print "one_pair"
            score += 200
            return score
        print "high card"
        return score

    def flush(self):
        suit = self.cards[0].get_suit()
        return all([card.get_suit() == suit for card in self.cards])

    def straight(self):
        start = self.cards[0].get_value()
        for card in self.cards[1:]:
            if card.get_value() == (start + 1):
                start = card.get_value()
            else:
                return False
        return True

    def straight_flush(self):
        return (self.straight() and self.flush())

    def royal_flush(self):
        return ((self.cards[0].get_name() == '10') and self.straight_flush())

    def _pair(self):
        count = 0
        names = [card.get_name() for card in self.cards]
        for i in range(len(names)):
            if (names[0:i] + names[i+1:]).count(names[i]) == 1:
                count += 1
        return count

    def one_pair(self):
        return self._pair() == 2

    def two_pair(self):
        if self.three_of_kind():
            return False
        return self._pair() == 4

    def _of_a_kind(self):
        count = {}
        names = [card.get_name() for card in self.cards]
        for name in names:
            if name not in count:
                count[name] = 1
            else:
                count[name] += 1
        return max(count.values())

    def three_of_kind(self):
        return self._of_a_kind() == 3

    def four_of_a_kind(self):
        return self._of_a_kind() == 4

    def full_house(self):
        return (self.one_pair() and self.three_of_kind())

    def high_card(self):
        return max([card.get_value() for card in self.cards])

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return u'&lt;&gt;'.join([repr(card) for card in self.cards]).encode('utf-8')



def run_hand(h):
    H = Hand(h)
    print H
    print H.determine_strength()


rand_hand = []

while len(rand_hand) &lt; 5:
    c = Card(random.choice(Card.card_suits.keys()), random.choice(Card.card_values.keys()))
    if c not in rand_hand:
        rand_hand.append(c)




rf = [Card('hearts', 'ace'), Card('hearts', 'king'), Card('hearts', 'queen'),
           Card('hearts', 'jack'), Card('hearts', '10')]
sf = [Card('spades', '9'), Card('spades', '8'), Card('spades', '7'),
           Card('spades', '6'), Card('spades', '5')]
foak = [Card('spades', 'ace'), Card('hearts', 'ace'), Card('clubs', 'ace'),
           Card('diamonds', 'ace'), Card('spades', '5')]
fh = [Card('spades', 'ace'), Card('hearts', 'ace'), Card('clubs', 'ace'),
           Card('diamonds', 'king'), Card('spades', 'king')]
f = [Card('spades', 'ace'), Card('spades', '10'), Card('spades', '2'),
           Card('spades', '5'), Card('spades', '7')]
s = [Card('spades', '6'), Card('spades', '5'), Card('clubs', '4'),
           Card('diamonds', '3'), Card('hearts', '2')]
toak = [Card('spades', 'ace'), Card('diamonds', 'ace'), Card('clubs', 'ace'),
           Card('diamonds', 'king'), Card('spades', '10')]
tp = [Card('spades', 'ace'), Card('diamonds', 'ace'), Card('clubs', 'king'),
           Card('diamonds', 'king'), Card('spades', '10')]
op = [Card('spades', 'ace'), Card('diamonds', 'ace'), Card('clubs', '9'),
           Card('diamonds', 'king'), Card('spades', '10')]
hc = [Card('spades', 'ace'), Card('diamonds', '10'), Card('clubs', '9'),
           Card('diamonds', 'king'), Card('spades', '5')]

run_hand(rand_hand)
print "-----Royal Flush-----"
run_hand(rf)
print "-----Straight Flush-----"
run_hand(sf)
print "-----Four of a Kind-----"
run_hand(foak)
print "-----Full House-----"
run_hand(fh)
print "-----Flush-----"
run_hand(f)
print "-----Straight-----"
run_hand(s)
print "-----Three of a Kind-----"
run_hand(toak)
print "-----Two Pairs-----"
run_hand(tp)
print "-----One Pair-----"
run_hand(op)
print "-----High Card-----"
run_hand(hc)
</code></pre>

<p>NB: this is python2.7, I'll try to convert it to python3 for you <em>if you need</em>   </p>

python combinations