title: Improving python code- how to group list elements by their property values
body: <p>I have the following piece of code in Python, it is organizing(grouping) playing cards by their ranks. I did this in old-school way but I am sure there is a better way as Python is actually famous of that kind of thing.
  How can I do the same in shorter and more elegant way?</p>
  
  <p>Here is the method code:</p>
  
  <pre><code>def gatherRanks(self, hand):
          self.value1 = []
          self.value2 = []
          self.value3 = []
          self.value4 = []
  
          card1 = hand.cards[0]
          self.value1.append(card1)
  
          card2 = hand.cards[1]
          if card2.rank == card1.rank:
              self.value1.append(card2)
          else:
              self.value2.append(card2)
  
          card3 = hand.cards[2]
          if card3.rank == card1.rank:
              self.value1.append(card3)
          elif card3.rank == card2.rank:
              self.value2.append(card3)
          else:
              self.value3.append(card3)
  
          card4 = hand.cards[3]
          if card4.rank == card1.rank:
              self.value1.append(card4)
          elif card4.rank == card2.rank:
              self.value2.append(card4)
          elif card4.rank == card3.rank:
              self.value3.append(card4)
          else:
              self.value4.append(card4)
  
          card5 = hand.cards[4]
          if card5.rank == card1.rank:
              self.value1.append(card5)
          elif card5.rank == card2.rank:
              self.value2.append(card5)
          elif card5.rank == card3.rank:
              self.value3.append(card5)
          elif card5.rank == card4.rank:
              self.value4.append(card5)
  </code></pre>
  
  <p>The idea behind that method is to group cards by their RANKs (not suits). I also decided to have 4 self variables because it is  easier to use than the list. 
  The reason is quite simple: figuring out the hands later on. 
  Having cards grouped by ranks I can then easily check the figure, for instance:</p>
  
  <pre><code>#(checking if hand is a Trip)
  def isThreeOfKind(self, hand):
          self.gatherRanks(hand)
          return len(self.value1)==3 or len(self.value2)==3 or len(self.value3)==3
  </code></pre>
  
  <p>and so on, every check is a matter of 1 - 3 lines of code (except Straight which requires loop).</p>