A function to map the keys in a dictionary
Project description
Map Dictionary Keys
Installation
pip install map-dictionary-keys
Usage
from map_dictionary_keys import map_dictionary_keys
d = {
'some_key_to_map': 'value'
}
def some_mapping_function(key_name):
return key_name.upper()
mapped_dictionary = map_dictionary_keys(d, some_mapping_function)
In the above example, mapped_dictionary
will be mapped according to the function some_mapping_function
as follows:
mapped_dictionary = {
'SOME_KEY_TO_MAP': 'value'
}
This function will work for all levels of nested dictionaries. In the following example, both 'sub_dictionary'
and 'key_name'
will be converted as per the mapping function passed to map_dictionary_keys
.
dictionary = {
'sub_dictionary': {
'key_name': 'value'
}
}
It will also work for nested lists of dictionaries. For example, in the following example, 'key_name'
will be mapped according to the mapping function provided to map_dictionary_keys
.
dictionary = {
'list_of_dictionaries': [
{
'key_name': 'value'
}
]
}
This function does not currently work for lists nested beyond the first level. For example, in the following example, 'key_name'
will not be mapped according to the mapping function provided to map_dictionary_keys
.
dictionary = {
'my_list': [
[
{
'key_name': 'value'
}
]
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for map-dictionary-keys-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79005df488a44625a80516eccb61f209da85ce885b580e457cf232334c147641 |
|
MD5 | 9dbe521a343a77a265077942b937736a |
|
BLAKE2b-256 | e5049c90ab3beac152dfb9e3df6038a7eaa7504d38ac1159a723b1764dea8980 |
Hashes for map_dictionary_keys-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6250bf8f2e2963ca74336dd5a0d32d2d172584da0634f9a23376262dca46e72c |
|
MD5 | 7f0ed4cf5d5a7fa21f2110906e083258 |
|
BLAKE2b-256 | 4d2e10be189243efd9d7b95eae5e8f4ddcaa67c7661f72d0f4cd410f03ac8cf3 |