title: Combine multiple objects and create list of overlappng attributes in python
body: <p>I have a class like the following:</p>
  
  <pre><code>class test(object):
      def __init__(self, ID, A, B, C, D, E):
          self.ID = ID
          self.A = A
          self.B = B
          self.C = C
          self.D = D
          self.E = E
  </code></pre>
  
  <p>And multiple objects in a list:</p>
  
  <pre><code>test1 = test(6124, 6, 'Tim', 'Football', 'Soccer', 'USA')
  test2 = test(6124, 7, 'Joe', 'Basketball', 'Soccer', 'USA')
  test3 = test(6188, 8, 'Joe', 'Basketball', 'Soccer', 'USA')
  test4 = test(6188, 9, 'Joe', 'Basketball', 'Soccer', 'USA')
  test5 = test(6188, 10, 'Tim', 'Football', 'Soccer', 'USA')
  
  objects_list = [test1, test2, test3, test4, test5]
  </code></pre>
  
  <p>I want to merge these objects based on their ID attribute and for the remaining attributes, just make a list of the individual objects:</p>
  
  <p>For this example, the result would be two objects (as only two unique IDs), one of which would have attributes:</p>
  
  <pre><code>self.ID = 6124
  self.A = [6, 7]
  self.B = ['Tim', 'Joe']
  self.C = ['Football', 'Basketball']
  self.D = ['Soccer', 'Soccer']
  self.E = ['USA', 'USA]
  </code></pre>
  
  <p>How can I merge the objects in the list in this way? I am looking for a solution which does not need me to name any attributes but the name of the   attribute on which I am merging (<code>ID</code>). It would be extra nice if this solution could be generalized to merge on multiple attributes at once (say <code>ID</code> and <code>A</code> and <code>E</code>). </p>
  
  <p>Thanks!
  Jack</p>