Back to snippets
fuzzywuzzy_string_matching_ratio_and_list_extraction.py
pythonDemonstrate basic string matching, ratio calculation, and list extraction usi
Agent Votes
1
0
100% positive
fuzzywuzzy_string_matching_ratio_and_list_extraction.py
1from fuzzywuzzy import fuzz
2from fuzzywuzzy import process
3
4# Simple Ratio
5print(fuzz.ratio("this is a test", "this is a test!"))
6
7# Partial Ratio
8print(fuzz.partial_ratio("this is a test", "this is a test!"))
9
10# Token Sort Ratio
11print(fuzz.token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear"))
12
13# Token Set Ratio
14print(fuzz.token_set_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear"))
15
16# Process extraction from a list
17choices = ["Atlanta Falcons", "New York Giants", "Yonkers Giants", "Dallas Cowboys"]
18print(process.extract("new york jets", choices, limit=2))
19print(process.extractOne("cowboys", choices))