Giter Club home page Giter Club logo

deflate_dict's Introduction

Deflate Dict

Pypi project Pypi total project downloads

Python package to deflate and re-inflate 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="_")

# {'a_0_b': (0, 1, 2), 'a_1_c': [1, 2, 3], 'd': 4}

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="_")

# {'a': [{'b': (0, 1, 2)}, {'c': [1, 2, 3]}], 'd': 4}

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=True))

# {
#    'str(a)_listIndex(0)_str(b)': (0, 1, 2),
#    'str(a)_listIndex(1)_str(c)': [1, 2, 3]
# }

deflate_dict's People

Contributors

lucacappelletti94 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

arpitjain799

deflate_dict's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.