Skip to main content

Handy Dict

A library with some handy utils to deal with dictionaries that contain arrays

This file will become your README and also the index of your documentation.

Install

pip install handy-dict

How to use

Let's start with a dictionary

pikachu = {
  "name": "pikachu",
  "moves": [
    {
      "move": {
        "name": "mega-punch",
        "url": "https://pokeapi.co/api/v2/move/5/"
      }
    },
    {
      "move": {
        "name": "pay-day",
        "url": "https://pokeapi.co/api/v2/move/6/"
      }
    },
    {
      "move": {
        "name": "thunder-punch",
        "url": "https://pokeapi.co/api/v2/move/9/"
      }
    }
  ],
  "stats": [
    {
      "base_stat": 90,
      "effort": 2,
      "stat": {
        "name": "speed",
        "url": "https://pokeapi.co/api/v2/stat/6/"
      }
    },
    {
      "base_stat": 50,
      "effort": 0,
      "stat": {
        "name": "special-defense",
        "url": "https://pokeapi.co/api/v2/stat/5/"
      }
    }
  ]
}

apply_keyed

from handy_dict import apply_keyed

With handy-dict you can apply a function to the keys inside a dictionary, say you want to take name out of stat, go from something like this:

{
  "base_stat": 50,
  "effort": 0,
  "stat": {
    "name": "special-defense",
    "url": "https://pokeapi.co/api/v2/stat/5/"
  }
}

to this:

{
  "base_stat": 50,
  "name": "special-defense"
}

The function transform_stat is just a little helper that will transform the stats array in our pikachu dictionary and return a new array, that will replace the stats in a copy of the original dict:

def transform_stat(stat_array):
    return {
        stat["stat"]["name"]: stat["base_stat"] 
        for stat in stat_array 
    } 
modified_pikachu = apply_keyed(pikachu,["stats"], transform_stat)
modified_pikachu["stats"]
{'speed': 90, 'special-defense': 50}

return_keyed

from handy_dict import return_keyed

handy-dict also makes it easy to return multiple values from a dictionary, iterating through keys and arrays:

return_keyed(pikachu, ["moves","move","name"])
['mega-punch', 'pay-day', 'thunder-punch']

Metadata

Release files for handy-dict 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for handy-dict 0.1.0
File Size Uploaded
handy_dict-0.1.0.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for handy-dict 0.1.0
File Interpreter ABI Platform
handy_dict-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / handy_dict-0.1.0.tar.gz

Download URL handy_dict-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
65594dc4742ee4f41e5cb4b83161b85b2d5f7601c678aa185bac783b646b49cf
BLAKE2b-256 checksum
How to use checksums
93e8fd3f431fb6366a53d3257ae53f83035f769a388e07ca974c723cce8e4c40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.10

Release files / handy_dict-0.1.0-py3-none-any.whl

Download URL handy_dict-0.1.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1ad3bf27c4107257d58318c0e8af8175cef39b261998c9eac40427191938c2e
BLAKE2b-256 checksum
How to use checksums
71d40a25db23fb5403d5cf4d50f511c07889dcc9652543c4932feb3a65343de0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.10
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page