Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

python - Using Process.extract in fuzzywuzzy and the all max similar choices for given query and choices

query = ('Hello','bye' , 'yellow')
choices= ('Hello','can', 'sweet' , 'lye' , 'fellow' , 'Hello')

Now I want to use fuzzywuzzy process. Extract() to get the best choice with maximum similarity ratio for all of my queries. And if there are two choices with the same maximum ratio, I want both of them.

My expected output is-- (list for similarity ratio for all my query elements)

('Hello', 100), ('Hello', 100)]
('lye' , 80)
('fellow' , 80 ) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please refer to https://pypi.org/project/fuzzywuzzy/

An example from above link page.

>>> choices = ["Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys"]
>>> process.extract("new york jets", choices, limit=2)
    [('New York Jets', 100), ('New York Giants', 78)]
>>> process.extractOne("cowboys", choices)
    ("Dallas Cowboys", 90)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...