def edit_script_to_strings(edit_script, use_colors=True):
    """Convert an edit script to a pair of strings representing the operation in a human readable way.

    :param edit_script: The edit script as a list of operations, where each operation is a dictionary.
    :param use_colors: Boolean indicating whether to use terminal color codes to color the output.
    :return: Tuple with text corresponding to the first pronunciation and the text of the second one.
    """
    colors = collections.defaultdict(str)

    if use_colors:
        colors['red'] = '\x1b[31m'
        colors['normal'] = '\x1b[m'
        colors['green'] = '\x1b[32m'
        colors['on_red'] = '\x1b[41m'

    src_txt = ''
    dst_txt = ''
    for op in edit_script:
        if op['op_code'] == 'match':
            width = max(len(op['from_symbol']), len(op['to_symbol']))
            if op['from_symbol'] == op['to_symbol']:
                src_txt += '{green}{from_symbol: ^{width}}{normal}'.format(**_combine_dicts(colors,
                                                                                            op,
                                                                                            {'width': width}))
                dst_txt += '{green}{to_symbol: ^{width}}{normal}'.format(**_combine_dicts(colors,
                                                                                          op,
                                                                                          {'width': width}))
            else:
                src_txt += '{red}{from_symbol: ^{width}}{normal}'.format(**_combine_dicts(colors,
                                                                                          op,
                                                                                          {'width': width}))
                dst_txt += '{red}{to_symbol: ^{width}}{normal}'.format(**_combine_dicts(colors,
                                                                                        op,
                                                                                        {'width': width}))

        elif op['op_code'] == 'insert':
            space = ' '*len(op['to_symbol'])
            src_txt += '{on_red}{space}{normal}'.format(space=space, **_combine_dicts(colors,  op))
            dst_txt += '{red}{to_symbol}{normal}'.format(**_combine_dicts(colors, op))

        elif op['op_code'] == 'delete':
            space = ' '*len(op['from_symbol'])
            src_txt += '{red}{from_symbol}{normal}'.format(**_combine_dicts(colors, op))
            dst_txt += '{on_red}{space}{normal}'.format(space=space, **_combine_dicts(colors, op))

        elif op['op_code'] == 'noninsert':
            continue

        src_txt += ' '
        dst_txt += ' '

    return src_txt, dst_txt
def edit_script_to_strings ( edit_script , use_colors = True ) : colors = collections . defaultdict ( str ) if use_colors : colors [ 'red' ] = '\x1b[31m' colors [ 'normal' ] = '\x1b[m' colors [ 'green' ] = '\x1b[32m' colors [ 'on_red' ] = '\x1b[41m' src_txt = '' dst_txt = '' for op in edit_script : if op [ 'op_code' ] == 'match' : width = max ( len ( op [ 'from_symbol' ] ) , len ( op [ 'to_symbol' ] ) ) if op [ 'from_symbol' ] == op [ 'to_symbol' ] : src_txt += '{green}{from_symbol: ^{width}}{normal}' . format ( ** _combine_dicts ( colors , op , { 'width' : width } ) ) dst_txt += '{green}{to_symbol: ^{width}}{normal}' . format ( ** _combine_dicts ( colors , op , { 'width' : width } ) ) else : src_txt += '{red}{from_symbol: ^{width}}{normal}' . format ( ** _combine_dicts ( colors , op , { 'width' : width } ) ) dst_txt += '{red}{to_symbol: ^{width}}{normal}' . format ( ** _combine_dicts ( colors , op , { 'width' : width } ) ) elif op [ 'op_code' ] == 'insert' : space = ' ' * len ( op [ 'to_symbol' ] ) src_txt += '{on_red}{space}{normal}' . format ( space = space , ** _combine_dicts ( colors , op ) ) dst_txt += '{red}{to_symbol}{normal}' . format ( ** _combine_dicts ( colors , op ) ) elif op [ 'op_code' ] == 'delete' : space = ' ' * len ( op [ 'from_symbol' ] ) src_txt += '{red}{from_symbol}{normal}' . format ( ** _combine_dicts ( colors , op ) ) dst_txt += '{on_red}{space}{normal}' . format ( space = space , ** _combine_dicts ( colors , op ) ) elif op [ 'op_code' ] == 'noninsert' : continue src_txt += ' ' dst_txt += ' ' return src_txt , dst_txt
Convert an edit script to a pair of strings representing the operation in a human readable way.

    :param edit_script: The edit script as a list of operations, where each operation is a dictionary.
    :param use_colors: Boolean indicating whether to use terminal color codes to color the output.
    :return: Tuple with text corresponding to the first pronunciation and the text of the second one.