#!/usr/bin/env python3## Copyright 2007 Doug Hellmann.#"""SequenceMatcher example"""#end_pymotw_headerimport difflibs1 = [1, 2, 3, 5, 6, 4]s2 = [2, 3, 5, 4, 6, 1]print('Initial data:')print('s1 =', s1)print('s2 =', s2)print('s1 == s2:', s1 == s2)print()matcher = difflib.SequenceMatcher(None, s1, s2)for tag, i1, i2, j1, j2 in reversed(matcher.get_opcodes()):if tag == 'delete':print('Remove {} from positions [{}:{}]'.format(s1[i1:i2], i1, i2))print(' before =', s1)del s1[i1:i2]elif tag == 'equal':print('s1[{}:{}] and s2[{}:{}] are the same'.format(i1, i2, j1, j2))elif tag == 'insert':print('Insert {} from s2[{}:{}] into s1 at {}'.format(s2[j1:j2], j1, j2, i1))print(' before =', s1)s1[i1:i2] = s2[j1:j2]elif tag == 'replace':print(('Replace {} from s1[{}:{}] ''with {} from s2[{}:{}]').format(s1[i1:i2], i1, i2, s2[j1:j2], j1, j2))print(' before =', s1)s1[i1:i2] = s2[j1:j2]print(' after =', s1, '\n')print('s1 == s2:', s1 == s2)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型