Skip to main content

Utility/Helper functions build around dictionary data type in Python

Project description

Nestdict

Makes Nested Dictionaries Easy To Use

Python

Nestdict is used to simplify various operations on nested and plain dictionaries. It offers various functions to simplify your work.

  • Pass the dictionary object in the function of your need.
  • Get the result you want.

Functions

  • find_in_map(dict_obj, key1, key2, key3, ...) finds the value for nested keys if exist.
    obj = {
        "cars_owned": {
          "sedan": 1,
          "suv": 3,
          "hatchback": 2
        },
    }
    
    suv_cars_count = find_in_map(obj, "cars_owned", "suv")
    
    print(suv_cars_count) >> 3
    
  • all_keys(dict_obj) returns all the keys present in the object
    obj = {
       "cars_owned": {
         "sedan": 1,
         "suv": 3,
         "hatchback": 2
       },
    }
    
    car_types = all_keys(obj["cars_owned"])
    all_keys_in_obj = all_keys(obj)
    
    print(car_types) >> ["sedan", "suv", "hachback"]
    print(all_keys_in_obj) >> ["cars_owned", "sedan", "suv", "hachback"]
    
  • check_keys(dict_obj, [key1, key2, ...]) check if all the keys exist in object
    obj = {
       "cars_owned": {
         "sedan": 1,
         "suv": 3,
         "hatchback": 2
       },
    }
    
    is_sedan_and_suv_exist = check_keys(obj, ["sedan", "suv"])
    
    print(is_sedan_and_suv_exist) >> True
    

Installation

Nestdict requires Python3.6 +

Install using pip

pip install nestdict

Import functions from nestdict

from nestdict import find_in_map,check_keys

Development

Want to contribute? Great!

  1. Fork the repository.
  2. Clone the Project and create a seprate branch with function name(/feature/<featureName>) or bug name(/bugfix/<brief>).
  3. Make sure to clearly describe the functionality and use case.
  4. Make a pull request.

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

nestdict-0.1.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

nestdict-0.1.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page