code: def _to_zip_product(sweep: Sweep) -> Product:
      
      if not isinstance(sweep, Product):
          sweep = Product(sweep)
      if not all(isinstance(f, Zip) for f in sweep.factors):
          factors = [f if isinstance(f, Zip) else Zip(f) for f in sweep.factors]
          sweep = Product(*factors)
      for factor in sweep.factors:
          for term in cast(Zip, factor).sweeps:
              if not isinstance(term, SingleSweep):
                  raise ValueError('cannot convert to zip-product form: {}'
                                   .format(sweep))
      return sweep
docs: Converts sweep to a product of zips of single sweeps, if possible.