code: def remove_random_edge_until_has_leaves(self) -> None:
          
          while True:
              leaves = set(self.iter_leaves())
              if leaves:
                  return
              self.remove_random_edge()
docs: Remove random edges until there is at least one leaf node.