You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中FuzzyWuzzy循环调用process.extract无输出问题排查

问题出在没打印返回值哦!

嘿,这问题很常见——你只是调用了process.extract()但没把它的返回值输出出来呀!

FuzzyWuzzy的process.extract()函数不会自动打印结果,它是返回一个包含匹配项和相似度得分的列表。你的代码里只执行了这个函数,但没对返回值做任何操作,自然看不到结果啦。

修正后的代码很简单,只要把process.extract()的结果打印出来就行:

from fuzzywuzzy import fuzz, process
choices = ['hello', 'world', 'today']
others = ['happy', 'today', 'colours']
for i in choices:
    print(f"匹配关键词: {i}")
    # 接收并打印process.extract的返回结果
    matches = process.extract(i, others)
    print(f"匹配结果: {matches}\n")

运行这段代码你就能看到类似这样的输出:

匹配关键词: hello
匹配结果: [('happy', 40), ('today', 0), ('colours', 0)]

匹配关键词: world
匹配结果: [('colours', 29), ('happy', 0), ('today', 0)]

匹配关键词: today
匹配结果: [('today', 100), ('happy', 0), ('colours', 0)]

如果只想要最匹配的那个结果,可以用process.extractOne(),它会返回单个元组(匹配项+得分),用法类似:

print(f"最匹配结果: {process.extractOne(i, others)}")

内容的提问来源于stack exchange,提问作者user5847481

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:38:30