pyrule
Deduplicate a list while keeping the first occurrence and its position — with
the one detail set() gets wrong: types are preserved.
Install
pip install pyrule
The problem
list(set([1, 1.0, True])) # -> [1] three rows silently become one
dedupe([1, 1.0, True]) # -> [1, 1.0, True]
In Python 1 == 1.0 == True, so naive deduplication loses records. For data
coming out of CSV, JSON or a database, those are three different values.
Usage
from pyrule import dedupe, dedupe_key
dedupe(["b", "a", "b"]) # ['b', 'a'] order kept
dedupe([{"a": 1}, {"a": 1}, {"a": 2}]) # two dicts kept
dedupe_key(1), dedupe_key(1.0) # ('int', '1'), ('float', '1.0')
Rules
| Input | Key |
|---|---|
str / int / float / bool / None |
(type name, repr) |
| anything else | canonical JSON, else repr |
Order is always preserved and the returned items are the originals, not copies.
License
MIT
Metadata
Release files for pyrule 0.0.2
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 | |
|---|---|---|---|---|
| pyrule-0.0.2.tar.gz | 3.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyrule-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.5 kB
Release files / pyrule-0.0.2.tar.gz
| Download URL | pyrule-0.0.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fd1a501a636ad9c2ba913204eac17b0e74f378914a535944a56a4f2eca19875
|
|
BLAKE2b-256 checksum How to use checksums |
aa6cb322ebc9eac30b5bb04f956b76ab259693bff1070d37976bd9de0b37acd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / pyrule-0.0.2-py3-none-any.whl
| Download URL | pyrule-0.0.2-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85a3c84f9b039fb5713d1350435a8f724bbefd359b73814cb5543a80a2454e44
|
|
BLAKE2b-256 checksum How to use checksums |
581971cc2e1b5e513f4d59c5b1bf1656234563f2712b03325ca2b1c9e89ea201
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for pyrule 0.0.2
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.