transpose-dict


Nametranspose-dict JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/LucaCappelletti94/transpose_dict
SummaryPackage to transpose dictionaries across any axes, just like n-dimensional matrices.
upload_time2024-07-05 19:24:08
maintainerNone
docs_urlNone
authorLuca Cappelletti
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🎲 Transpose Dictionary

[![pip](https://badge.fury.io/py/transpose-dict.svg)](https://pypi.org/project/transpose-dict/)
![python](https://img.shields.io/pypi/pyversions/transpose-dict)
[![license](https://img.shields.io/pypi/l/transpose-dict)](https://github.com/LucaCappelletti94/deflate_dict/blob/master/LICENSE)
[![downloads](https://pepy.tech/badge/transpose-dict)](https://www.pepy.tech/projects/transpose-dict)
[![github](https://github.com/LucaCappelletti94/transpose_dict/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/transpose_dict/actions/)

Python package to transpose Python dictionaries.

Multilevel dictionaries can be viewed as projections of sparse n-dimensional matrices: as such, you can transpose them on any of their axes.

The package provides a function that allows you to transpose a dictionary on any of its axes.

## Installing the transpose_dict package

As usual, just use pip as follows:

```shell
pip install transpose_dict
```

## Basic usage example

```python
from transpose_dict import transpose_dict # or from transpose_dict import TD, for brevity

your_dictionary = {
    "a" : {
        "0" : {
            "I" : [1, 2, 3],
            "II" : [4, 5, 6]
        }
    },
    "b" : {
        "0" : {
            "I" : [8, 9, 10],
            "II" : [467, 23, 23]
        },
        "1" : {
            "III" : [6, 7, 9]
        }
    }
}

transpose_dict(your_dictionary, axis=0) # The given dictionary does not change
#> {"b": {"0": {"I": [8, 9, 10], "II": [467, 23, 23]}, "1": {"III": [6, 7, 9]}}, "a": {"0": {"I": [1, 2, 3], "II": [4, 5, 6]}}}
transpose_dict(your_dictionary, axis=1) # The new main axis is the one with ("0", "1")
#> {"0": {"a": {"I": [1, 2, 3], "II": [4, 5, 6]}, "b": {"I": [8, 9, 10], "II": [467, 23, 23]}}, "1": {"b": {"III": [6, 7, 9]}}}
transpose_dict(your_dictionary, axis=2) # The new main axis is the one with ("I", "II", "III")
#> {"I": {"a": {"0": [1, 2, 3]}, "b": {"0": [8, 9, 10]}}, "III": {"b": {"1": [6, 7, 9]}}, "II": {"a": {"0": [4, 5, 6]}, "b": {"0": [467, 23, 23]}}}
```

## License

The software is released under the MIT license.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LucaCappelletti94/transpose_dict",
    "name": "transpose-dict",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Luca Cappelletti",
    "author_email": "cappelletti.luca94@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/26/82/29b46aa2bfd10c714b454efeeed7bbda091d3321650a76a871d8740e7ec9/transpose_dict-1.2.1.tar.gz",
    "platform": null,
    "description": "# \ud83c\udfb2 Transpose Dictionary\n\n[![pip](https://badge.fury.io/py/transpose-dict.svg)](https://pypi.org/project/transpose-dict/)\n![python](https://img.shields.io/pypi/pyversions/transpose-dict)\n[![license](https://img.shields.io/pypi/l/transpose-dict)](https://github.com/LucaCappelletti94/deflate_dict/blob/master/LICENSE)\n[![downloads](https://pepy.tech/badge/transpose-dict)](https://www.pepy.tech/projects/transpose-dict)\n[![github](https://github.com/LucaCappelletti94/transpose_dict/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/transpose_dict/actions/)\n\nPython package to transpose Python dictionaries.\n\nMultilevel dictionaries can be viewed as projections of sparse n-dimensional matrices: as such, you can transpose them on any of their axes.\n\nThe package provides a function that allows you to transpose a dictionary on any of its axes.\n\n## Installing the transpose_dict package\n\nAs usual, just use pip as follows:\n\n```shell\npip install transpose_dict\n```\n\n## Basic usage example\n\n```python\nfrom transpose_dict import transpose_dict # or from transpose_dict import TD, for brevity\n\nyour_dictionary = {\n    \"a\" : {\n        \"0\" : {\n            \"I\" : [1, 2, 3],\n            \"II\" : [4, 5, 6]\n        }\n    },\n    \"b\" : {\n        \"0\" : {\n            \"I\" : [8, 9, 10],\n            \"II\" : [467, 23, 23]\n        },\n        \"1\" : {\n            \"III\" : [6, 7, 9]\n        }\n    }\n}\n\ntranspose_dict(your_dictionary, axis=0) # The given dictionary does not change\n#> {\"b\": {\"0\": {\"I\": [8, 9, 10], \"II\": [467, 23, 23]}, \"1\": {\"III\": [6, 7, 9]}}, \"a\": {\"0\": {\"I\": [1, 2, 3], \"II\": [4, 5, 6]}}}\ntranspose_dict(your_dictionary, axis=1) # The new main axis is the one with (\"0\", \"1\")\n#> {\"0\": {\"a\": {\"I\": [1, 2, 3], \"II\": [4, 5, 6]}, \"b\": {\"I\": [8, 9, 10], \"II\": [467, 23, 23]}}, \"1\": {\"b\": {\"III\": [6, 7, 9]}}}\ntranspose_dict(your_dictionary, axis=2) # The new main axis is the one with (\"I\", \"II\", \"III\")\n#> {\"I\": {\"a\": {\"0\": [1, 2, 3]}, \"b\": {\"0\": [8, 9, 10]}}, \"III\": {\"b\": {\"1\": [6, 7, 9]}}, \"II\": {\"a\": {\"0\": [4, 5, 6]}, \"b\": {\"0\": [467, 23, 23]}}}\n```\n\n## License\n\nThe software is released under the MIT license.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package to transpose dictionaries across any axes, just like n-dimensional matrices.",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/LucaCappelletti94/transpose_dict"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "268229b46aa2bfd10c714b454efeeed7bbda091d3321650a76a871d8740e7ec9",
                "md5": "280ee6ef6e800cfff38a119bc581bf07",
                "sha256": "e94695b6dae9bcc5ef4c2be2df12a0af4be90dfe32e070cb0e8862e1d1dc8f72"
            },
            "downloads": -1,
            "filename": "transpose_dict-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "280ee6ef6e800cfff38a119bc581bf07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4615,
            "upload_time": "2024-07-05T19:24:08",
            "upload_time_iso_8601": "2024-07-05T19:24:08.933350Z",
            "url": "https://files.pythonhosted.org/packages/26/82/29b46aa2bfd10c714b454efeeed7bbda091d3321650a76a871d8740e7ec9/transpose_dict-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-05 19:24:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "LucaCappelletti94",
    "github_project": "transpose_dict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "transpose-dict"
}
        
Elapsed time: 0.26379s