【发布时间】:2015-11-11 21:18:31
【问题描述】:
我正在尝试编写一个程序,将打乱的名称列表与常规名称的大列表逐个字符进行比较。
例如,假设加扰列表中的一个名称是B@B St@r#,我正在尝试将该名称与常规名称列表进行比较,看看它有多少个相同的字符,或者它是否完美匹配使用常规列表的名称之一。
到目前为止我的代码是这样的:
for ch in list2: ##list 2 has the decrypted names
parts = ch.split()
decryptedfirst_names.append(parts[0]) ##Im trying to compare first names for now
for ch in list1: ##list1 is a big list of regular names
part = ch.split()
first_names.append(part[0])
matching = []
for ch in first_names:
if ch in decryptedfirst_names and ch not in matching:
matching.append(ch)
print(matching)
然后这段代码将只打印匹配的名称。
我需要帮助来计算按位置匹配的字符的确切数量,这样我可以将它放在一个百分比中,比如 80% 匹配等等,如果可能的话,初学者可以编程。
【问题讨论】:
-
Google 制造的diff-match-patch package 有很多您正在寻找的东西。您可能最感兴趣的是
diff -
我很感激,我只是在寻找我可以做的事情并了解更多。
标签: python list string-comparison similarity