spiketools.utils.base.relabel_keys

spiketools.utils.base.relabel_keys(indict, new_keys)[source]

Relabel keys in a dictionary.

Parameters:
indictdict

Dictionary with key names to be updated.

new_keysdict

Dictionary defining new key names. Each key should be the current name, and each value the name to update to.

Returns:
outdictdict

Dictionary with updated key names.

Examples

Relabel a set of keys in a dictionary:

>>> dictionary = {'spike_name' : 'a1', 'spike_type' : 0}
>>> new_keys = {'spike_name' : 'name', 'spike_type' : 'type'}
>>> relabel_keys(dictionary, new_keys)
{'name': 'a1', 'type': 0}