py-dual-sorter


Namepy-dual-sorter JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummarySort content by two keys
upload_time2025-08-07 03:17:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords iteration utilities
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            * website: <https://arrizza.com/py-dual-sorter.html>
* installation: see <https://arrizza.com/setup-common.html>

## Summary

This project is for content that needs to be iterated in two different ways.
It allows two keys ("left" and "right") to be defined at the same time.

## How to use

#### load()

Use ```load(path)``` to load a json file.
Use ```load(path, validate=True)``` to check for duplicate keys.

Sample json content is:

```text
[
    [
        "left3",    # <== the "left" key
        "right2",   # <== the "right" key
        "infoA"     # <== info for this entry & keys; Can be "null" if there is no info
    ],
    [
        "left2",
        "right3",
        null
    ],
]
```

#### save()

Use ```save(path)``` to save the current content to a json file.

#### add()

Use ```add(left, right, info)``` to add a new entry.
The left and right keys have to be unique, otherwise an exception is thrown.

Note that info is optional ```add(left, right)``` or explicitly set to None.

#### all_by_left() and all_by_right()

To iterate in sorted order by the left key, use:

```python
pds = PyDualSorter()
pds.load('path/to/file')
for left, right, info in pds.all_by_left():
    print(f'left key is  {left}')
    print(f'right key is {left}')
    print(f'info is      {info}')
```

To iterate in sorted order by the right key, use:

```python
pds = PyDualSorter()
pds.load('path/to/file')
for left, right, info in pds.all_by_left():   # <== note that left key is still present
    print(f'left key is  {left}')
    print(f'right key is {left}')
    print(f'info is      {info}')
```

#### is_left() and is_right()

Use ```is_left(val)``` to check if a value is a left key.
Use ```is_right(val)``` to check if a value is a right key.

#### get_left_info() and get_right_info()

Use ```info = pds.get_left_info(left)``` to get the info associated with the given left key.
Use ```info = pds.get_right_info(right)``` to get the info associated with the given right key.

#### get_left() and get_right()

Use ```right = pds.get_right(left)``` to get the matching right key for the given left key.
Use ```left = pds.get_left(right)``` to get the matching left key for the given right key.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "py-dual-sorter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "\"J. Arrizza\" <cppgent0@gmail.com>",
    "keywords": "iteration, utilities",
    "author": null,
    "author_email": "\"J. Arrizza\" <cppgent0@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/35/71/1476dc74a83503f7991d90567c43c741765d6ae8ebf3e685608a83a63584/py_dual_sorter-0.2.0.tar.gz",
    "platform": null,
    "description": "* website: <https://arrizza.com/py-dual-sorter.html>\n* installation: see <https://arrizza.com/setup-common.html>\n\n## Summary\n\nThis project is for content that needs to be iterated in two different ways.\nIt allows two keys (\"left\" and \"right\") to be defined at the same time.\n\n## How to use\n\n#### load()\n\nUse ```load(path)``` to load a json file.\nUse ```load(path, validate=True)``` to check for duplicate keys.\n\nSample json content is:\n\n```text\n[\n    [\n        \"left3\",    # <== the \"left\" key\n        \"right2\",   # <== the \"right\" key\n        \"infoA\"     # <== info for this entry & keys; Can be \"null\" if there is no info\n    ],\n    [\n        \"left2\",\n        \"right3\",\n        null\n    ],\n]\n```\n\n#### save()\n\nUse ```save(path)``` to save the current content to a json file.\n\n#### add()\n\nUse ```add(left, right, info)``` to add a new entry.\nThe left and right keys have to be unique, otherwise an exception is thrown.\n\nNote that info is optional ```add(left, right)``` or explicitly set to None.\n\n#### all_by_left() and all_by_right()\n\nTo iterate in sorted order by the left key, use:\n\n```python\npds = PyDualSorter()\npds.load('path/to/file')\nfor left, right, info in pds.all_by_left():\n    print(f'left key is  {left}')\n    print(f'right key is {left}')\n    print(f'info is      {info}')\n```\n\nTo iterate in sorted order by the right key, use:\n\n```python\npds = PyDualSorter()\npds.load('path/to/file')\nfor left, right, info in pds.all_by_left():   # <== note that left key is still present\n    print(f'left key is  {left}')\n    print(f'right key is {left}')\n    print(f'info is      {info}')\n```\n\n#### is_left() and is_right()\n\nUse ```is_left(val)``` to check if a value is a left key.\nUse ```is_right(val)``` to check if a value is a right key.\n\n#### get_left_info() and get_right_info()\n\nUse ```info = pds.get_left_info(left)``` to get the info associated with the given left key.\nUse ```info = pds.get_right_info(right)``` to get the info associated with the given right key.\n\n#### get_left() and get_right()\n\nUse ```right = pds.get_right(left)``` to get the matching right key for the given left key.\nUse ```left = pds.get_left(right)``` to get the matching left key for the given right key.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Sort content by two keys",
    "version": "0.2.0",
    "project_urls": {
        "Download": "https://bitbucket.org/arrizza-public/py-dual-sorter/get/master.zip",
        "Source": "https://bitbucket.org/arrizza-public/py-dual-sorter/src/master",
        "Website": "https://arrizza.com/py-dual-sorter"
    },
    "split_keywords": [
        "iteration",
        " utilities"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "35711476dc74a83503f7991d90567c43c741765d6ae8ebf3e685608a83a63584",
                "md5": "5b39cf8225c5ddd254fb883d1efd3b7c",
                "sha256": "263ccff05cad90e5ae94162b5e74fd7021bb0e0ed0373d6dd0ce935646ebb8dd"
            },
            "downloads": -1,
            "filename": "py_dual_sorter-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5b39cf8225c5ddd254fb883d1efd3b7c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 4900,
            "upload_time": "2025-08-07T03:17:09",
            "upload_time_iso_8601": "2025-08-07T03:17:09.028519Z",
            "url": "https://files.pythonhosted.org/packages/35/71/1476dc74a83503f7991d90567c43c741765d6ae8ebf3e685608a83a63584/py_dual_sorter-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-07 03:17:09",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "codeberg": false,
    "bitbucket_user": "arrizza-public",
    "bitbucket_project": "py-dual-sorter",
    "lcname": "py-dual-sorter"
}
        
Elapsed time: 4.95166s