Package to transpose dictionaries across any axes, just like n-dimensional matrices.
Project description
🎲 Transpose Dictionary
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.
Project details
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)
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | e94695b6dae9bcc5ef4c2be2df12a0af4be90dfe32e070cb0e8862e1d1dc8f72 |
|
MD5 | 280ee6ef6e800cfff38a119bc581bf07 |
|
BLAKE2b-256 | 268229b46aa2bfd10c714b454efeeed7bbda091d3321650a76a871d8740e7ec9 |