title: Is there some generic data structure to compare lists of objects and find most equal among them?
body: <p>I will use Python to show a code (because this solution for Python written code) but this question is language independent.</p>
  
  <p>Let's say I have 2 lists of objects. I can't use object ids as primary keys for those objects.</p>
  
  <p>An object can look like(real objects much more complicated and have nested structures):</p>
  
  <pre><code>class A():
      def __init__(self, prop1, prop2, prop3):
          self.prop1 = prop1
          self.prop2 = prop2
          self.prop3 = prop3
  </code></pre>
  
  <p>Lists look like:</p>
  
  <pre><code>list1 = [A(1, 2, 3), A(4, 5, 6), A(7, 8, 9)]
  list2 = [A(1, 10, 11), A(4, 5, 6), A(1, 4, 9), A(10, 11, 12)]
  </code></pre>
  
  <p>While comparing objects I use the number of equal properties as a score.</p>
  
  <p>For example:</p>
  
  <pre><code>A(1, 2, 3) == A(1, 10, 11) gives 1, because only 1 == 1
  A(4, 5, 6) == A(4, 5, 6) gives 3, because 4 == 4, 5 == 5, 6 == 6
  A(7, 8, 9) == A(10, 11, 12) gives 0, because there are no equal items
  </code></pre>
  
  <p>After comparison of all objects form <code>list1</code> with every object from <code>list2</code>, I get something I call similarity matrix which will look like this:</p>
  
  <pre><code>[
      [1, 0, 1, 0],
      [0, 3, 0, 0],
      [0, 0, 1, 0],
  ]
  </code></pre>
  
  <p>After that I take max element from list, which is <code>3</code>, delete row and column to which this number belongs (row=1, column=1), delete by position those object from <code>list1</code>, <code>list2</code> and repeat until there are no items in similarity matrix which are greater than threshold(zero in current example).</p>
  
  <p>Similarity matrix after a first step:</p>
  
  <pre><code>[
      [1, 1, 0],
      [0, 1, 0],
  ]
  </code></pre>
  
  <p>Lists after a first step:</p>
  
  <pre><code>list1 = [A(1, 2, 3), A(7, 8, 9)]
  list2 = [A(1, 10, 11), A(1, 4, 9), A(10, 11, 12)]
  </code></pre>
  
  <p>By those actions, I will get most equal objects by popping them by position from lists and everything left in lists I mark as not equal.</p>
  
  <p>I want to know if I reinventing a wheel and there is some data structure which can help with this? Do you see any visible improvements which can speed up current solution?</p>