【发布时间】:2020-06-06 09:11:50
【问题描述】:
list = ['Apple','Banana','Cucumber']
string = 'The other day as I ate a bnana in the park'
for x in range(len(list)):
if list[x] in string:
do a little dance
这是我现在代码的要点,尽管我的实际字符串和列表要长得多。该字符串是用户提交的,所以我必须预料到拼写错误/速记/大写字母,并且没有用我能想到的每个拼写错误填写我的列表或解析字符串的每个单词,我不知道如何解决这个问题。
我正在寻找一个模糊的包含 if 语句。我已经查看了fuzzywuzzy 文档,但我不确定在这种情况下如何使它工作。
有这样的功能吗?
threshold = 80
for x in range(len(list):
if fuzzy.contain(list[x],string) > threshold:
do a little dance:
感谢您的帮助。
【问题讨论】:
-
我查看了fuzzywuzzy 文档,但不确定如何在这种情况下使用它。 你能说得更具体些吗?
标签: python if-statement fuzzy-search