Maps the elements of an iterable to categories using bisect
pip install catmapper
Tested against Windows 10 / Python 3.10 / Anaconda
Args:
iterable (iterable): The iterable containing the elements to be categorized.
cats (list[list, list] | list[tuple | list]): The categories used for mapping. It can be provided in two formats:
- A list of two lists, where the first list represents the category labels and the second list represents
the corresponding values. The values don't have to be in ascending order.
- A list of pairs, where each pair consists of a category label and its corresponding value.
Returns:
list[tuple]: A list of tuples, where each tuple contains an element from the 'iterable' and its corresponding category.
Raises:
TypeError: If the 'cats' argument is not in the expected format or if the values are not in ascending order.
Examples:
import sys
from catmapper import category_mapping
# Example 1: Using a list with 2 lists
cats_ = [['barato', 'mais ou menos', 'caro', 'muito caro', 'absurdo'],
[1.3, 2, 3.1, 6.5, sys.maxsize]]
cervejas = [
("original", 2.5),
("Skol", 0.5),
("becks", 16),
("brahma", 1.4),
("heineken", 5.5),
]
print(category_mapping(cervejas, cats_))
# Output:
# [(('original', 2.5), 'caro'), (('Skol', 0.5), 'barato'), (('becks', 16), 'absurdo'),
# (('brahma', 1.4), 'mais ou menos'), (('heineken', 5.5), 'muito caro')]
# Example 2: Using a list of pairs
cats_ = [
("barato", 1.3),
("mais ou menos", 2),
("caro", 3.1),
("muito caro", 6.5),
("absurdo", sys.maxsize),
]
# also ok:
cats_ = [
("muito caro", 6.5),
("mais ou menos", 2),
("caro", 3.1),
("absurdo", sys.maxsize),
("barato", 1.3),
]
print(category_mapping(cervejas, cats_))
# Output:
# [(('original', 2.5), 'caro'), (('Skol', 0.5), 'barato'), (('becks', 16), 'absurdo'),
# (('brahma', 1.4), 'mais ou menos'), (('heineken', 5.5), 'muito caro')]
Metadata
Release files for catmapper 0.10
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 | Actions |
|---|---|---|---|---|
| catmapper-0.10.tar.gz | 3.9 kB | Without provenance | Details for catmapper-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| catmapper-0.10-py3-none-any.whl | Python 3 | none | any | Details for catmapper-0.10-py3-none-any.whl |
Total release size: 9.8 kB
Release files / catmapper-0.10.tar.gz
| Download URL | catmapper-0.10.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d56c9cfcdd28f7aa599fc7d2dc44bb1f605feb75b4afdfd630d014c836fa505f
|
|
BLAKE2b-256 checksum How to use checksums |
1bc7d69daf52df092edeaf5e2ed0294716557b42e94579db1046a4da26c07add
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / catmapper-0.10-py3-none-any.whl
| Download URL | catmapper-0.10-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1141b60c422f12f02949c2a4c70d86296452c218cfedadeac122cbb1770f51cc
|
|
BLAKE2b-256 checksum How to use checksums |
949bfdb7e3aaedfcce97687994436ada8a61b055e4f470beacaa11bf41dff939
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for catmapper 0.10
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.