|
| 1 | +# 🎲 Transpose Dictionary |
| 2 | + |
| 3 | +[](https://pypi.org/project/transpose-dict/) |
| 4 | + |
| 5 | +[](https://github.com/LucaCappelletti94/deflate_dict/blob/master/LICENSE) |
| 6 | +[](https://www.pepy.tech/projects/transpose-dict) |
| 7 | +[](https://github.com/LucaCappelletti94/transpose_dict/actions/) |
| 8 | + |
| 9 | +Python package to transpose Python dictionaries. |
| 10 | + |
| 11 | +Multilevel dictionaries can be viewed as projections of sparse n-dimensional matrices: as such, you can transpose them on any of their axes. |
| 12 | + |
| 13 | +The package provides a function that allows you to transpose a dictionary on any of its axes. |
| 14 | + |
| 15 | +## Installing the transpose_dict package |
| 16 | + |
| 17 | +As usual, just use pip as follows: |
| 18 | + |
| 19 | +```shell |
| 20 | +pip install transpose_dict |
| 21 | +``` |
| 22 | + |
| 23 | +## Basic usage example |
| 24 | + |
| 25 | +```python |
| 26 | +from transpose_dict import transpose_dict # or from transpose_dict import TD, for brevity |
| 27 | + |
| 28 | +your_dictionary = { |
| 29 | + "a" : { |
| 30 | + "0" : { |
| 31 | + "I" : [1, 2, 3], |
| 32 | + "II" : [4, 5, 6] |
| 33 | + } |
| 34 | + }, |
| 35 | + "b" : { |
| 36 | + "0" : { |
| 37 | + "I" : [8, 9, 10], |
| 38 | + "II" : [467, 23, 23] |
| 39 | + }, |
| 40 | + "1" : { |
| 41 | + "III" : [6, 7, 9] |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +transpose_dict(your_dictionary, axis=0) # The given dictionary does not change |
| 47 | +#> {"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]}}} |
| 48 | +transpose_dict(your_dictionary, axis=1) # The new main axis is the one with ("0", "1") |
| 49 | +#> {"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]}}} |
| 50 | +transpose_dict(your_dictionary, axis=2) # The new main axis is the one with ("I", "II", "III") |
| 51 | +#> {"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]}}} |
| 52 | +``` |
| 53 | + |
| 54 | +## License |
| 55 | + |
| 56 | +The software is released under the MIT license. |
0 commit comments