DEV Community

petercour
petercour

Posted on

1

Fuzzywuzzy and Python

What's fuzzywuzzy?

It's a string matching module. A string is variable that can store (and modify) text. It uses Levenshtein Distance to calculate the differences between sequences in a simple-to-use package.

Fuzzy string matching like a boss.
How to get started? First you should know Python programming.

pip install fuzzywuzzy

Then you can use it like this:

#!/usr/bin/python3
from fuzzywuzzy import fuzz
from fuzzywuzzy import process

r = fuzz.ratio("this is a test", "this is a test!")
print(r)

r = fuzz.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")
print(r)

This outputs the ratio:

97
91

You can run this from the interpreter:

>>> fuzz.ratio("this is a test", "this is a test!")
    97

Another example of fuzzywuzzy:

>>> from fuzzywuzzy import fuzz
>>> fuzz.ratio("this is a test","a test this is")
50

Related links:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
maximoguerrero profile image
Maximo Guerrero

I would suggest to also use word embeddings when doing name matching, for example fuzzywuzzy fails when comparing Bill and William. Robert and Bob. When using word embeddings you vectors will be closer together. Welcome to NLP

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay