title: Python. Identity in sets of objects. And hashing
body: <p>How do __hash__ and __eq__ use in identification in sets?
  For example some code that should help to solve some domino puzzle:</p>
  
  <pre><code>class foo(object):
      def __init__(self, one, two):
          self.one = one
          self.two = two
      def __eq__(self,other):
          if (self.one == other.one) and (self.two == other.two): return True
          if (self.two == other.one) and (self.one == other.two): return True
          return False
      def __hash__(self):
          return hash(self.one + self.two)
  
  s = set()
  
  for i in range(7):
      for j in range(7):
          s.add(foo(i,j))
  len(s) // returns 28 Why?
  </code></pre>
  
  <p>If i use only __eq__() len(s) equals 49. Its ok because as i understand objects (1-2 and 2-1 for example) not same, but represent same domino. So I have added hash function.<br>
  Now it works the way i want, but i did not understand one thing: hash of 1-3 and 2-2 should be same so they should counted like same object and shouldn't added to set. But they do! Im stuck.</p>