# Maps the elements of an iterable to categories using bisect
## pip install catmapper
#### Tested against Windows 10 / Python 3.10 / Anaconda
```python
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')]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/catmapper",
"name": "catmapper",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "bisect,mapping",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1b/c7/d69daf52df092edeaf5e2ed0294716557b42e94579db1046a4da26c07add/catmapper-0.10.tar.gz",
"platform": null,
"description": "\r\n# Maps the elements of an iterable to categories using bisect\r\n\r\n## pip install catmapper\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda \r\n\r\n\t\r\n```python\r\nArgs:\r\n\titerable (iterable): The iterable containing the elements to be categorized.\r\n\tcats (list[list, list] | list[tuple | list]): The categories used for mapping. It can be provided in two formats:\r\n\t\t- A list of two lists, where the first list represents the category labels and the second list represents\r\n\t\t the corresponding values. The values don't have to be in ascending order.\r\n\t\t- A list of pairs, where each pair consists of a category label and its corresponding value.\r\n\r\nReturns:\r\n\tlist[tuple]: A list of tuples, where each tuple contains an element from the 'iterable' and its corresponding category.\r\n\r\nRaises:\r\n\tTypeError: If the 'cats' argument is not in the expected format or if the values are not in ascending order.\r\n\r\nExamples:\r\n\timport sys\r\n\tfrom catmapper import category_mapping\r\n\t# Example 1: Using a list with 2 lists\r\n\tcats_ = [['barato', 'mais ou menos', 'caro', 'muito caro', 'absurdo'],\r\n\t\t\t [1.3, 2, 3.1, 6.5, sys.maxsize]]\r\n\tcervejas = [\r\n\t\t(\"original\", 2.5),\r\n\t\t(\"Skol\", 0.5),\r\n\t\t(\"becks\", 16),\r\n\t\t(\"brahma\", 1.4),\r\n\t\t(\"heineken\", 5.5),\r\n\t]\r\n\tprint(category_mapping(cervejas, cats_))\r\n\t# Output:\r\n\t# [(('original', 2.5), 'caro'), (('Skol', 0.5), 'barato'), (('becks', 16), 'absurdo'),\r\n\t# (('brahma', 1.4), 'mais ou menos'), (('heineken', 5.5), 'muito caro')]\r\n\r\n\t# Example 2: Using a list of pairs\r\n\tcats_ = [\r\n\t\t(\"barato\", 1.3),\r\n\t\t(\"mais ou menos\", 2),\r\n\t\t(\"caro\", 3.1),\r\n\t\t(\"muito caro\", 6.5),\r\n\t\t(\"absurdo\", sys.maxsize),\r\n\t]\r\n\t# also ok:\r\n\tcats_ = [\r\n\t\t(\"muito caro\", 6.5),\r\n\t\t(\"mais ou menos\", 2),\r\n\t\t(\"caro\", 3.1),\r\n\t\t(\"absurdo\", sys.maxsize),\r\n\t\t(\"barato\", 1.3),\r\n\t]\r\n\tprint(category_mapping(cervejas, cats_))\r\n\t# Output:\r\n\t# [(('original', 2.5), 'caro'), (('Skol', 0.5), 'barato'), (('becks', 16), 'absurdo'),\r\n\t# (('brahma', 1.4), 'mais ou menos'), (('heineken', 5.5), 'muito caro')]\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Maps the elements of an iterable to categories using bisect",
"version": "0.10",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/catmapper"
},
"split_keywords": [
"bisect",
"mapping"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "949bfdb7e3aaedfcce97687994436ada8a61b055e4f470beacaa11bf41dff939",
"md5": "a57c6015363aa95324080fba577a407d",
"sha256": "1141b60c422f12f02949c2a4c70d86296452c218cfedadeac122cbb1770f51cc"
},
"downloads": -1,
"filename": "catmapper-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a57c6015363aa95324080fba577a407d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5943,
"upload_time": "2023-07-03T01:03:51",
"upload_time_iso_8601": "2023-07-03T01:03:51.882567Z",
"url": "https://files.pythonhosted.org/packages/94/9b/fdb7e3aaedfcce97687994436ada8a61b055e4f470beacaa11bf41dff939/catmapper-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1bc7d69daf52df092edeaf5e2ed0294716557b42e94579db1046a4da26c07add",
"md5": "f5a8627ec66125274e08aa8626056464",
"sha256": "d56c9cfcdd28f7aa599fc7d2dc44bb1f605feb75b4afdfd630d014c836fa505f"
},
"downloads": -1,
"filename": "catmapper-0.10.tar.gz",
"has_sig": false,
"md5_digest": "f5a8627ec66125274e08aa8626056464",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3896,
"upload_time": "2023-07-03T01:03:53",
"upload_time_iso_8601": "2023-07-03T01:03:53.633824Z",
"url": "https://files.pythonhosted.org/packages/1b/c7/d69daf52df092edeaf5e2ed0294716557b42e94579db1046a4da26c07add/catmapper-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-03 01:03:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "catmapper",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "catmapper"
}