def od_replace_key(od, key, new_key, *args, **kw):
multi = kw.get('<STR_LIT>', False) or isinstance(key, list)<EOL>if multi:<EOL><INDENT>if len(key) != len(new_key):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (len(key), len(new_key)))<EOL><DEDENT>if args:<EOL><INDENT>new_value = args[<NUM_LIT:0>]<EOL>if len(new_key) != len(new_value):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(len(new_key), len(new_value)))<EOL><DEDENT>for k_old, k_new, v_new in zip(key, new_key, new_value):<EOL><INDENT>od_replace_key(od, k_old, k_new, v_new)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for k_old, k_new in zip(key, new_key):<EOL><INDENT>od_replace_key(od, k_old, k_new)<EOL><DEDENT><DEDENT>return<EOL><DEDENT>if args:<EOL><INDENT>value = args[<NUM_LIT:0>]<EOL><DEDENT>if new_key == key:<EOL><INDENT>if args:<EOL><INDENT>OrderedDict.__setitem__(od, key, value)<EOL><DEDENT>return<EOL><DEDENT>if new_key in od: <EOL><INDENT>OrderedDict.__delitem__(od, new_key)<EOL><DEDENT>if PY2:<EOL><INDENT>_map = od._OrderedDict__map<EOL>link = _map[key]<EOL>link[<NUM_LIT:2>] = new_key<EOL>del _map[key]<EOL>_map[new_key] = link<EOL>val = dict.pop(od, key)<EOL>if args:<EOL><INDENT>val = value<EOL><DEDENT>dict.__setitem__(od, new_key, val)<EOL><DEDENT>else:<EOL><INDENT>found = False<EOL>keys = [] <EOL>for k in od:<EOL><INDENT>if k == key:<EOL><INDENT>found = True<EOL>continue<EOL><DEDENT>if found:<EOL><INDENT>keys.append(k)<EOL><DEDENT><DEDENT>getitem = dict.__getitem__<EOL>setitem = OrderedDict.__setitem__<EOL>delitem = OrderedDict.__delitem__<EOL>v = getitem(od, key)<EOL>delitem(od, key)<EOL>if args:<EOL><INDENT>v = value<EOL><DEDENT>setitem(od, new_key, v)<EOL>for k in keys:<EOL><INDENT>v = getitem(od, k)<EOL>delitem(od, k)<EOL>setitem(od, k, v)<EOL><DEDENT><DEDENT>
Replace key(s) in OrderedDict ``od`` by new key(s) in-place (i.e.,
preserving the order(s) of the key(s))

Optional new value(s) for new key(s) can be provided as a positional
argument (otherwise the old value(s) will be used):

    od_replace_key(od, key, new_key, new_value)

To replace multiple keys, pass argument ``key`` as a list instance,
or explicitly pass a keyword argument ``multi=True``:

    od_replace_key(od, keys, new_keys, [new_values,] multi=True)