Skip to main content

Dict copy

Project description

dict-copy

Extension methods for copying dictionaries

Installation

Use pip to install the package:

pip install dict-copy

Usage

This package provides some functions to copy a dict

Simple clone

from dictcopy import dictcopy


obj = {
    "name": "Jeff",
    "lastname": "Aguilar",
    "age": 28,
    "email": "jeff.aguilar.06@gmail.com"
}

obj1 = dictcopy.clone(obj)

Copy some values

If you want to clone the dictionary, but only with some values, you can specify them.

obj1 = dictcopy.clone(obj, {
    "name",
    "lastname",
    "email"
})

Strict mode

By default, when you specify fields that do not exist in the source dictionary, they will simply be skipped.

But, you could change this behavior by changing the strict_mode property to True. You will get a KeyError

obj1 = dictcopy.clone(obj, {
    "name",
    "lastname",
    "email",
    "ocupation"
}, strict_mode=True)

Extract values

If you want to remove some values, extract might help. will return a new dictionary with the fields removed from the source dictionary

obj1 = dictcopy.extract(obj, {
    "age",
    "email"
})

You can also apply strict mode to validate that each field exists in the source dictionary. You will get a KeyError

obj1 = dictcopy.extract(obj, {
    "age",
    "email"
}, strict_mode=True)

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

dictcopy-0.0.4.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file dictcopy-0.0.4.tar.gz.

File metadata

  • Download URL: dictcopy-0.0.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for dictcopy-0.0.4.tar.gz
Algorithm Hash digest
SHA256 152bcb13e95eec3f522b6c6e2cfe01b7c26d5d198907a7b2f97d7e6b20336de8
MD5 559193c05ca47ef0a9c01ed42ae50059
BLAKE2b-256 39b52fe91fd618659dc99d59ae38498c3da8d37e58cb5f5bb728546893e82411

See more details on using hashes here.

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