Skip to main content

Merge nested dicts according to a few specific rules

Project description

Prio merge

Merge two dictionaries on a deep level with one taking precedent over another, and by using a few rules:

If keys exist in just one of the dictionaries, it will be merged in the final dictionary

If two keys exist in the same nested depth, one of these things will happen

  • if the values have different types, prioritized dict value will take remain
  • if both values are lists, they will be combined according by appending the non-prioritized list to the other and then removing duplicates by casting to a list. This means that list order can not be guaranteed It also means that any list will end the recursive nature of the merge
  • if both values are dicts, the keys will be combined recursively using these rules
  • otherwise take the value from the prioritized dictionary

Usage

from prio_merge import prio_merge

prio_dict = {}

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

prio_merge-0.0.2.tar.gz (1.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prio_merge-0.0.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file prio_merge-0.0.2.tar.gz.

File metadata

  • Download URL: prio_merge-0.0.2.tar.gz
  • Upload date:
  • Size: 1.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.9

File hashes

Hashes for prio_merge-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d604fc8b1f89e3bc94ebc278464ed434fdf745e20cbfbbfc1dd770a894e8881f
MD5 d5d690f3a0455c44bd8bf771e7323297
BLAKE2b-256 79c03c230760cebc932e9e98a255384e9bc76717c14f51de98bc420af39862e5

See more details on using hashes here.

File details

Details for the file prio_merge-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: prio_merge-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.9

File hashes

Hashes for prio_merge-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e36136fb1e1621bbfbd551a199078623cd0211c36b0c7a398c39410fe64ddc71
MD5 df99d80040b82f9d0c59c8f76f9b2b39
BLAKE2b-256 6aa9f64a4168acada7d8f85eaa434a840e37e46fc2e235f2f7004e62ab66f92a

See more details on using hashes here.

Supported by

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