Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 1.01 KB

2016-01-06-py-difflib.md

File metadata and controls

30 lines (19 loc) · 1.01 KB
layout title date categories tags
post
Python:difflib字符串差别
2016-01-05 11:26:25 -0800
Coding
Python

difflib是可以比较文件和字符串差异的库, 能实现类似linux命令diff的效果. 如果比较文件夹和文件, 可以使用filecmp模块.

快速上手

计算两个字符串相似度

difflib.SequenceMatcher(None, 'abcde', 'zbcde').ratio()
<iframe src="http://platinhom.github.io/ManualHom/Coding/Python/python-2.7.11rc1-docs-html/library/difflib.html" width="100%" height="600px"></iframe>

Reference

  1. Python-difflib
  2. 用PYTHON计算文本的相似度
  3. python-Levenshtein几个计算字串相似度的函数解析