def _convert_complex_fields_into_simple_fields(self):
        if not self.complex_field_runs:
            return

        fields = []
        field = None
        separate_triggered = False
        previous_run = None

        runs_to_remove_by_field = {}
        runs_to_remove = set()

        # All of the complex field runs need to be wrapped in simple fields,
        # and then the runs need to be removed from their original container
        # The new simple fields that contain the runs are inserted into the
        # structure and the parent links are updated

        # First create all the necessary simple fields and group the runs into
        # their simple fields.
        for run in self.complex_field_runs:
            for child in run.children:
                if field is not None and previous_run is not None:
                    if previous_run.parent is not run.parent:
                        # scope has changed
                        runs_to_remove_by_field[field] = runs_to_remove
                        runs_to_remove = set()
                        fields.append(field)
                        field = wordprocessing.SimpleField(instr=field.instr, children=[])

                if isinstance(child, wordprocessing.FieldChar):
                    separate_triggered = False
                    runs_to_remove.add(run)
                    if child.is_type_begin():
                        field = wordprocessing.SimpleField(children=[])
                    elif child.is_type_end():
                        if field is not None:
                            runs_to_remove_by_field[field] = runs_to_remove
                            runs_to_remove = set()
                            fields.append(field)
                            field = None
                    elif child.is_type_separate():
                        separate_triggered = True

                if field is None:
                    pass
                elif separate_triggered:
                    field.children.append(run)
                    runs_to_remove.add(run)
                elif isinstance(child, wordprocessing.FieldCode):
                    field.instr = child.content
                    runs_to_remove.add(run)
            previous_run = run

        # Next, remove all of the runs from the run's current parent, and
        # inject the field in their place.
        for field in fields:
            runs_to_remove = runs_to_remove_by_field.get(field, set())
            if not field.children:
                continue
            first_run = field.children[0]
            previous_parent_new_children = []
            for child in first_run.parent.children:
                if child is first_run:
                    # This is the insertion point of the new field
                    previous_parent_new_children.append(field)
                elif runs_to_remove not in child:
                    previous_parent_new_children.append(child)
            first_run.parent.children = previous_parent_new_children

            # If we don't do this, the field's parent will be None. That will
            # break the hierarchy.
            field.parent = first_run.parent

            # Update the run parent links to point to the field, since the
            # field is now the run's new parent.
            for run in field.children:
                run.parent = field
dataset/ETHPy150Open CenterForOpenScience/pydocx/pydocx/export/base.py/PyDocXExporter._convert_complex_fields_into_simple_fields/swapped operands of `not in`