I'm looking to replace the keys of a dict
to shorter variants so that it can be sent across the wire in a compact form. Is there a way to updating a key, rather than creating a new item in in the dict
and deleting the old?
What I'm 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'm unsure of dict
's internals. However, it seems that something like update_key
might be able to avoid needing to delete the old key.