code: def valid_sequences(self):
          
          valid_sets = [[x] for x in self.possible_items if x['left'] == 0]
          change = True
          niter = 200
          while change and niter > 0:
              change = False
              niter -=1
              for possible in sorted(self.possible_items, key=lambda x:x['left']):
                  for current_valid in valid_sets[:]:
                      if possible['left'] == current_valid[-1]['right']:
                          if current_valid + [possible] not in valid_sets:
                              if current_valid[-1]['left'] != current_valid[-1]['right'] or possible['left'] != possible['right']: #avoids Null insertion twice
                                  valid_sets.append(current_valid + [possible])
                                  change = True
          if not niter:
              raise Exception('too many iterations')
          return valid_sets
docs: Returns list