问题
I have the following input-
query = 'Total replenishment lead time (in workdays)'
choices = ['PLANNING_TIME_FENCE_CODE', 'BUILD_IN_WIP_FLAG','Lead_time_planning', 'Total replenishment lead time 1', 'Total replenishment lead time 2']
print(process.extract(query, choices))
I get the following output-
[('Total replenishment lead time 1', 92), ('Total replenishment lead time 2', 92), ('Lead_time_planning', 50), ('PLANNING_TIME_FENCE_CODE', 36), ('BUILD_IN_WIP_FLAG', 26)]
But I just want all the best choices with a maximum similarity ratio even if the ratio is similar for two choices.
Please help.
回答1:
If I understand your question correct you would like to receive the following output:
[('Total replenishment lead time 1', 92), ('Total replenishment lead time 2', 92)]
You can achieve this by filtering the results of process.extract
matches = process.extract(query, choices, limit=None)
max_ratio = matches[0][1]
best_matches = []
for match in matches:
if match[1] != max_ratio:
break
best_matches.append(match)
来源:https://stackoverflow.com/questions/65407585/using-process-extract-in-fuzzywuzzy-and-the-all-max-similar-choices