title: Creating Set of objects of user defined class in python
body: <pre><code>table = set([])
  
  class GlobeLearningTable(object):
      def __init__(self,mac,port,dpid):
  
          self.mac = mac
          self.port = port
          self.dpid = dpid
  
      def add(self):
  
          global table
          if self not in table:
              table.add(self)
  
  class LearningSwitch(object):
      def __init__ (self, connection, transparent):
         self.connection = connection
         self.transparent = transparent
         self.macToPort = {}
         connection.addListeners(self)
         self.hold_down_expired = _flood_delay == 0
  
      def _handle_PacketIn (self, event):
         packet = event.parsed
         self.macToPort[packet.src] = event.port # 1
         packet_src = str(packet.src)
         packet_mac = packet_src.upper()
         entry = GlobeLearningTable(packet_mac, event.port, dpid_to_str(self.connection.dpid))
         entry.add()
  </code></pre>
  
  <p>Problem : <code>entry.add()</code> method adds new object every time it is called and increments the items in the table.</p>
  
  <p>This should not happen because </p>
  
  <ol>
  <li>In the add method I am checking that is that object in the table or not , then I am adding that particular object.      </li>
  <li>Table is a set which is unordered list, which should not have duplicate objects.</li>
  </ol>
  
  <p>Help: is there any way in this set up I can add the object only when it's not in the table.</p>