def _build_moments(operation_by_qubits: list[list[ops.Operation]]) -> list[list[ops.Operation]]:
    """Builds moments from a list of operations grouped by qubits.

    Returns a list of moments from a list whose ith element is a list of operations applied
    to qubit i.
    """
    moments = []
    for moment in itertools.zip_longest(*operation_by_qubits):
        moments.append([op for op in moment if op is not None])
    return moments
Builds moments from a list of operations grouped by qubits.

    Returns a list of moments from a list whose ith element is a list of operations applied
    to qubit i.
    
cirq-core/cirq/transformers/gauge_compiling/gauge_compiling.py