Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python - difflib #207

Open
4 tasks
junxnone opened this issue May 20, 2020 · 1 comment
Open
4 tasks

Python - difflib #207

junxnone opened this issue May 20, 2020 · 1 comment

Comments

@junxnone
Copy link
Owner

junxnone commented May 20, 2020

  • 对比序列

Reference

Brief

  • 输出 html 格式的对比结果

方法

Name Description
Class SequenceMatcher 比较任何类型片段
Class Differ
Class HtmlDiff
context_diff
get_close_matches
ndiff
restore
unified_diff
diff_bytes

Examples

  • 比较两个字符串的相似度
import difflib
s1 = 'abcdefghij'
s2 = 'bbcdefghij'
difflib.SequenceMatcher(None, s1, s2).quick_ratio()
0.9
  • 和顺序无关
import difflib
s1 = 'abcdefghij'
s2 = 'jihgfedcba'
difflib.SequenceMatcher(None, s1, s2).quick_ratio()
1.0
@junxnone
Copy link
Owner Author

#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant