Skip to main content

A library that applies arbitrary functions to each element of list type and dict type objects

Project description

pytransform

A library that applies arbitrary functions to each element of list type and dict type objects

Functions that defines the conversion process, which takes each element before conversion as an argument and returns each element after conversion, is called recursively, so it also supports nested list and dictionary.

Requirements

  • python 3.5, 3.6, 3.7, 3.8, 3.9

Installation

pip install cpyberry-pytransform

Usage

When you want to multiply each element of the list by 2, you can write:

import pytransform


def operation_double(element: int, origin: list) -> int:
	# The first argument contains each element of the original list.
	# The original list is stored in the second argument.
	return element * 2


pytransform.transform_list([1, 2, 3], operation_double)
# return [2, 4, 6]

pytransform.transform_list(
	origin=[1, 2, 3],
	operation=operation_double
)
# return [2, 4, 6]

When you want to insert "_neko" at the end of each key in the dictionary and "_inu" at the end of each value, you can write:

def operation_key(key: str, origin: dict, value: str):
	# The first argument contains each key of the original dictionary.
	# The original dictionary is stored in the second argument.
	# The third argument contains the value corresponding to each key in the original dictionary.
	return key + "_neko"


def operation_value(value: str, origin: dict, key: str):
	# The first argument contains each key of the original dictionary.
	# The original dictionary is stored in the second argument.
	# The third argument contains the value corresponding to each key in the original dictionary.
	return value + "_inu"


pytransform.transform_dictionary(
	origin={"meow": "woof"},
	operation_key=operation_key,
	operation_value=operation_value
)
# return {"meow_neko", "woof_inu"}

The above functions are called recursively, so they also support nested list and dictionary.

pytransform.transform_list([1, 2, [3, 4, 5]], operation_double)
# return [2, 4, [6, 8, 10]]

pytransform.transform_dictionary(
	origin={"meow": {"pows": "woof"}},
	operation_key=operation_key,
	operation_value=operation_value
)
# return {"meow_neko": {"pows_neko": "woof_inu"}}

Founder

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

cpyberry-pytransform-2.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

cpyberry_pytransform-2.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file cpyberry-pytransform-2.0.0.tar.gz.

File metadata

  • Download URL: cpyberry-pytransform-2.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/2.1.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for cpyberry-pytransform-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e6a1043b34e6d2639230dd4d9d5268f4a1ab02937e056fdd1784e09f07b68b92
MD5 be56979befead0f1c1f4cb624810fee2
BLAKE2b-256 5803571e3eaa0adf232bbb078bdf7ae5a4823e65cf583db5033c2758e38de1bf

See more details on using hashes here.

File details

Details for the file cpyberry_pytransform-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: cpyberry_pytransform-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/2.1.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for cpyberry_pytransform-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 460d0f578a5404f544c14b40f379cb47b30b693c5bbb34794f1ce1b97b9fa139
MD5 14cae1c5fde6ca0df372eb4b5dbec64a
BLAKE2b-256 6cf13df9c7e1db6699cf27645992a09fba4bb41826c9df8fc8f24f28858eae8b

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