I want to replace the keys dictwith shorter options so that they can be sent via cable in a compact form. Is there a way to update the key, rather than create a new item in dictand delete the old one?
What am I doing now:
>>> a = dict(long_key=None)
>>> a['l'] = a['long_key']
>>> del a['long_key']
What I would like to do is something like this:
>>> a = dict(long_key=None)
>>> a.update_key('long_key', 'l')
I am not sure about the internal elements dict. However, it seems that something like this update_keycan avoid the need to delete the old key.
source
share