nodes: 0, module; 1, function_definition; 2, function_name:remove; 3, parameters; 4, block; 5, identifier:self; 6, identifier:element; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:multiplicity; 15, None; 16, comment:"""Removes an element from the multiset.
  
          If no multiplicity is specified, the element is completely removed from the multiset:
  
          >>> ms = Multiset('aabbbc')
          >>> ms.remove('a')
          2
          >>> sorted(ms)
          ['b', 'b', 'b', 'c']
  
          If the multiplicity is given, it is subtracted from the element's multiplicity in the multiset:
  
          >>> ms.remove('b', 2)
          3
          >>> sorted(ms)
          ['b', 'c']
  
          It is not an error to remove more elements than are in the set:
  
          >>> ms.remove('b', 2)
          1
          >>> sorted(ms)
          ['c']
  
          This extends the :meth:`MutableSet.remove` signature to allow specifying the multiplicity.
  
          Args:
              element:
                  The element to remove from the multiset.
              multiplicity:
                  An optional multiplicity i.e. count of elements to remove.
  
          Returns:
              The multiplicity of the element in the multiset before
              the removal.
  
          Raises:
              KeyError: if the element is not contained in the set. Use :meth:`discard` if
                  you do not want an exception to be raised.
          """; 17, assignment; 18, comparison_operator:element not in _elements; 19, block; 20, assignment; 21, boolean_operator; 22, block; 23, elif_clause; 24, elif_clause; 25, identifier:old_multiplicity; 26, identifier:_elements; 27, attribute; 28, identifier:element; 29, identifier:_elements; 30, raise_statement; 31, identifier:old_multiplicity; 32, call; 33, comparison_operator:multiplicity is None; 34, comparison_operator:multiplicity >= old_multiplicity; 35, delete_statement; 36, expression_statement; 37, comparison_operator:multiplicity < 0; 38, block; 39, comparison_operator:multiplicity > 0; 40, block; 41, identifier:self; 42, identifier:_elements; 43, identifier:KeyError; 44, attribute; 45, argument_list; 46, identifier:multiplicity; 47, None; 48, identifier:multiplicity; 49, identifier:old_multiplicity; 50, subscript; 51, augmented_assignment; 52, identifier:multiplicity; 53, integer:0; 54, raise_statement; 55, identifier:multiplicity; 56, integer:0; 57, expression_statement; 58, expression_statement; 59, identifier:_elements; 60, identifier:get; 61, identifier:element; 62, integer:0; 63, identifier:_elements; 64, identifier:element; 65, attribute; 66, identifier:old_multiplicity; 67, call; 68, augmented_assignment; 69, augmented_assignment; 70, identifier:self; 71, identifier:_total; 72, identifier:ValueError; 73, argument_list; 74, subscript; 75, identifier:multiplicity; 76, attribute; 77, identifier:multiplicity; 78, string:"Multiplicity must be not be negative"; 79, identifier:_elements; 80, identifier:element; 81, identifier:self; 82, identifier:_total
code: def remove(self, element, multiplicity=None):
          """Removes an element from the multiset.
  
          If no multiplicity is specified, the element is completely removed from the multiset:
  
          >>> ms = Multiset('aabbbc')
          >>> ms.remove('a')
          2
          >>> sorted(ms)
          ['b', 'b', 'b', 'c']
  
          If the multiplicity is given, it is subtracted from the element's multiplicity in the multiset:
  
          >>> ms.remove('b', 2)
          3
          >>> sorted(ms)
          ['b', 'c']
  
          It is not an error to remove more elements than are in the set:
  
          >>> ms.remove('b', 2)
          1
          >>> sorted(ms)
          ['c']
  
          This extends the :meth:`MutableSet.remove` signature to allow specifying the multiplicity.
  
          Args:
              element:
                  The element to remove from the multiset.
              multiplicity:
                  An optional multiplicity i.e. count of elements to remove.
  
          Returns:
              The multiplicity of the element in the multiset before
              the removal.
  
          Raises:
              KeyError: if the element is not contained in the set. Use :meth:`discard` if
                  you do not want an exception to be raised.
          """
          _elements = self._elements
          if element not in _elements:
              raise KeyError
          old_multiplicity = _elements.get(element, 0)
          if multiplicity is None or multiplicity >= old_multiplicity:
              del _elements[element]
              self._total -= old_multiplicity
          elif multiplicity < 0:
              raise ValueError("Multiplicity must be not be negative")
          elif multiplicity > 0:
              _elements[element] -= multiplicity
              self._total -= multiplicity
          return old_multiplicity