Skip to main content

🎲 Transpose Dictionary

pip python license downloads github

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:

pip install transpose_dict

Basic usage example

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transpose_dict-1.2.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file transpose_dict-1.2.1.tar.gz.

File metadata

  • Download URL: transpose_dict-1.2.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for transpose_dict-1.2.1.tar.gz
Algorithm Hash digest
SHA256 e94695b6dae9bcc5ef4c2be2df12a0af4be90dfe32e070cb0e8862e1d1dc8f72
MD5 280ee6ef6e800cfff38a119bc581bf07
BLAKE2b-256 268229b46aa2bfd10c714b454efeeed7bbda091d3321650a76a871d8740e7ec9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.1 This release

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page