🔍 groupbyScore – Group Similar Items Using Fuzzy Matching in Python
Overview
groupbyScore is a Python function that groups similar records from a list of dictionaries using fuzzy matching. It utilizes the rapidfuzz package for high-performance string similarity scoring.
📦 Dependencies
- Python 3.6+
rapidfuzz
Install with:
pip install rapidfuzz
🚀 Function Signature
groupbyScore(all_data, score, key)
Parameters
all_data(List[dict]): A list of dictionaries to be grouped.key(Callable): A function returning a tuple of values (e.g.,lambda x: (x["Notes"], x["page_num"])) used to compare and group.
⚙️ How It Works
-
Iterates over all item pairs in the dataset.
-
Compares each field in the
key(...)tuple:- Strings:
fuzz.partial_ratio> 80 - Integers: must match exactly
- Strings:
-
Groups items where all key fields match.
-
Yields:
- the group key
- the list of matching items
✅ Example Usage
from groupbyScore.groupbyScore import groupbyScore
data = [
{"Notes": "Chest Pain", "page_num": 1},
{"Notes": "chest pain", "page_num": 1},
{"Notes": "church", "page_num": 1},
{"Notes": "Fever", "page_num": 2},
{"Notes": "feverish", "page_num": 2}
]
# TUPLE
for key, group in groupbyScore(data, key=lambda x: (x["Notes"], x["page_num"]),score=90):
print("Group Key:", key)
print("Group Items:", group)
# STR
for key, group in groupbyScore(data, key=lambda x: x["Notes"],score=90):
print("Group Key:", key)
print("Group Items:", group)
📤 Example Output
#### OUTPUT 1
Group Key: ('Chest Pain', 1)
Group Items: [{'Notes': 'Chest Pain', 'page_num': 1}, {'Notes': 'chest pain', 'page_num': 1}]
Group Key: ('church', 1)
Group Items: [{'Notes': 'church', 'page_num': 1}]
Group Key: ('Fever', 2)
Group Items: [{'Notes': 'Fever', 'page_num': 2}, {'Notes': 'feverish', 'page_num': 2}]
#### OUTPUT 2
Group Key: Chest Pain
Group Items: [{'Notes': 'Chest Pain', 'page_num': 1}, {'Notes': 'chest pain', 'page_num': 1}]
Group Key: church
Group Items: [{'Notes': 'church', 'page_num': 1}]
Group Key: Fever
Group Items: [{'Notes': 'Fever', 'page_num': 2}, {'Notes': 'feverish', 'page_num': 2}]
📎 GitHub
Metadata
Release files for groupbyScore 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| groupbyscore-0.0.6.tar.gz | 2.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| groupbyscore-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.0 kB
Release files / groupbyscore-0.0.6.tar.gz
| Download URL | groupbyscore-0.0.6.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f0b0621cb04e4f37f6de7d61126b11602ba67428b8eeadd8f387bb4ca307843
|
|
BLAKE2b-256 checksum How to use checksums |
d7b6212ac71c55a3a4fb8939b4a6f4c700be79fc81b595817e4838711f50eb15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / groupbyscore-0.0.6-py3-none-any.whl
| Download URL | groupbyscore-0.0.6-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d063a20e95bee885d4a240f41a665abc559870ed40f45cc2c4df2f7e5643e9d
|
|
BLAKE2b-256 checksum How to use checksums |
c56dfe7711dac4107b048263f37ac3e40dcbf2cf2ca38d07845cfdc890d1c97b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for groupbyScore 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.