code: def switch(self, idx, control):
          
          old = None
          new = None
          if control == 'Q':
              if self.PQ[idx] == 1:
                  old = 'PQ'
                  new = 'PV'
              elif self.vQ[idx] == 1:
                  old = 'vQ'
                  new = 'vV'
          elif control == 'P':
              if self.PQ[idx] == 1:
                  old = 'PQ'
                  new = 'vQ'
              elif self.PV[idx] == 1:
                  old = 'PV'
                  new = 'vV'
          elif control == 'V':
              if self.PV[idx] == 1:
                  old = 'PV'
                  new = 'PQ'
              elif self.vV[idx] == 1:
                  old = 'vV'
                  new = 'vQ'
          elif control == 'v':
              if self.vQ[idx] == 1:
                  old = 'vQ'
                  new = 'PQ'
              elif self.vV[idx] == 1:
                  old = 'vV'
                  new = 'PV'
          if old and new:
              self.__dict__[old][idx] = 0
              self.__dict__[new][idx] = 1
docs: Switch a single control of <idx>