title: How to overload python sets to accept duplicates?
body: <p>I had taken a python coding test, which asked to create a class that overloads the builtin set(all the methods of sets must work). The only change between the set I was asked to create and the builtin sets is that my custom sets SHOULD store duplicates, and 2 more custom methods.</p>
  <p>Here is what I could come up with:</p>
  <pre><code>import builtins
  
  class Multiset(builtins.set):
      def __init__(self):
          super().__init__()
          self.my_set = builtins.set()
  
      def add(self, val):
          self.my_set.add(val)
  
      def remove(self, val):
          # removes one occurrence of val from the multiset, if any
          self.my_set.discard(val)
  
      def __contains__(self, val):
          # returns True when val is in the multiset, else returns False
          return val in self.my_set
  
      def __len__(self):
          # returns the number of elements in the multiset
          return len(self.my_set)
  </code></pre>
  <p>I have tried overriding multiple methods, but to no avail. I also couldn't find a method that defined this non-duplicate criteria for sets. So, how do I do this?</p>
  <p><strong>EDIT 1:</strong>
  Here is the problem description, if you want to see it.<br />
  <a href="https://i.stack.imgur.com/Pf7XA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pf7XA.jpg" alt="enter image description here" /></a></p>