python对比字符串相似度

python对比字符串相似度

  • 一. fuzzywuzzy
  • 二. difflib

一. fuzzywuzzy

需要安装python-Levenshtein

from fuzzywuzzy import fuzz

print(fuzz.ratio('a b c', 'a c b'))
print(fuzz.token_set_ratio('a b c', 'a c b'))

# 结果
60
100

二. difflib

import difflib

print(difflib.SequenceMatcher(None, 'a b c', 'a c b').ratio())
print(difflib.SequenceMatcher(None, 'a b c', 'a c b').quick_ratio())

# 结果
0.6
1.0

你可能感兴趣的:(python日常,python,开发语言,后端)