Skip to content

Python package to transpose dictionaries, just like sparse n-dimensional matrices.

License

Notifications You must be signed in to change notification settings

LucaCappelletti94/transpose_dict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎲 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.

About

Python package to transpose dictionaries, just like sparse n-dimensional matrices.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages