🎈🌵 Deflate Dict
Python package to deflate 🌵 and re-inflate 🎈 nested dictionaries.
How do I install this package?
As usual, just download it using pip:
pip install deflate_dict
Deflating a dictionary
A dictionary will be deflated down to its smallest non-further iterable elements, defined as those not containing lists or dictionaries.
from deflate_dict import deflate
D = {
"a": [
{
"b": (0, 1, 2)
},
{
"c": [1, 2, 3]
}
]
}
result = deflate(D, sep="_")
Inflate a dictionary
To reinflate a dictionary to its forgotten glory, just go with:
from deflate_dict import inflate
D = {"a_0_b": (0, 1, 2), "a_1_c": [1, 2, 3], "d": 4}
result = inflate(D, sep="_")
Handling and restoring mixed types
To deflate and re-inflate mixed types and restore them to the original type you can use the type_encode_key
keyword:
from deflate_dict import deflate
D = {
"a":[
{
"b":(0,1,2)
},
{
"c": [1,2,3]
}
]
}
print(deflate(D, sep="_", type_encode_key=False))
print(deflate(D, sep="_", type_encode_key=True))
License
This software is distributed under MIT license.