title: Python Poker hand single pair counter
body: <p>I wrote the program below to iterate through every possible poker hand and count how many of these hands are a single pair</p>
  
  <p><em>A hand is any 5 cards.<br>
  A single pair is when two cards of the same rank (number) and the other 3 cards of all different ranks  e.g. (1,2,1,3,4)</em></p>
  
  <p>I am representing the deck of cards as a list of numbers e.g.<br>
  - 1 = ACE<br>
  - 2 = Two<br>
  - 3 = Three<br>
   ...<br>
  - 11 = Jack<br>
  - 12 = Queen...</p>
  
  <p>The program seems to work find however,
  the number of single pair hands it finds = 1101984</p>
  
  <p>But according to multiple sources the correct answer is 1098240.</p>
  
  <p>Can anyone see where the error in my code is?</p>
  
  <pre><code>from itertools import combinations
  # Generating the deck
  deck = []
  for i in range(52):
      deck.append(i%13 + 1)
  
  def pairCount(hand):
      paircount = 0
      for i in hand:
          count = 0
          for x in hand:
              if x == i:
                  count += 1
          if count == 2:
              paircount += .5 #Adding 0.5 because each pair is counted twice
  
      return paircount
  
  count = 0
  for i in combinations(deck, 5): # loop through all combinations of 5
      if pairCount(i) == 1:
          count += 1
  
  print(count)
  </code></pre>