code: def set_weight(self, rule, weight):
          
          if not issubclass(rule.__class__, (Rule, RuleLeaf)):
              raise TypeError("Rule to set weight ({}) is not subclass "
                              "of {} or {}.".format(rule, Rule, RuleLeaf))
          assert (weight >= -1.0 and weight <= 1.0)
          try:
              ind = self._R.index(rule)
              self._W[ind] = weight
          except:
              self.add_rule(rule, weight)
docs: Set weight for rule in :attr:`R`.
  
          Adds the rule if it is not in :attr:`R`.