

def rename(self, old_key, new_key):
    "\n        Rename the key for a given value, without modifying sequence order.\n\n        For the case where new_key already exists this raise an exception,\n        since if new_key exists, it is ambiguous as to what happens to the\n        associated values, and the position of new_key in the sequence.\n\n        >>> od = OrderedDict()\n        >>> od['a'] = 1\n        >>> od['b'] = 2\n        >>> od.items()\n        [('a', 1), ('b', 2)]\n        >>> od.rename('b', 'c')\n        >>> od.items()\n        [('a', 1), ('c', 2)]\n        >>> od.rename('c', 'a')\n        Traceback (most recent call last):\n        ValueError: New key already exists: 'a'\n        >>> od.rename('d', 'b')\n        Traceback (most recent call last):\n        KeyError: 'd'\n        "
    if (new_key == old_key):
        return
    if (new_key in self):
        raise ValueError(('New key already exists: %r' % new_key))
    value = self[old_key]
    old_idx = self._sequence.index(old_key)
    self._sequence[old_idx] = new_key
    dict.__delitem__(self, old_key)
    dict.__setitem__(self, new_key, value)

dataset/ETHPy150Open editorconfig/editorconfig-vim/plugin/editorconfig-core-py/editorconfig/odict.py OrderedDict.rename/original