Every line of 'python rename dict key' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
16 def rename_key(d, key, new_name): 17 d[new_name] = d[key] 18 del d[key]
35 def rename_attribute(dictionary, old_key_name, new_key_name): 36 dictionary[new_key_name] = dictionary.pop(old_key_name)
1599 def rename_key(self, key: str, new_key: str) -> None: 1600 """ 1601 Rename the given *key* into *new_key* without changing the value of the ID. 1602 1603 :param key: The old key. 1604 :param new_key: The new key. 1605 """ 1606 if key == new_key: 1607 return 1608 1609 value = self[key] 1610 self._del(key) 1611 self._set(new_key, value) 1612 1613 id_info = self._id_infos[key] 1614 del self._id_infos[key] 1615 self._id_infos[new_key] = id_info 1616 1617 child_key = key + '._child' 1618 if child_key in self: 1619 child_cache = self[child_key] 1620 self._del(child_key) 1621 self._set(new_key + '._child', child_cache)
65 def _remap_keys(d): 66 return [{"k": k, "v": v} for k, v in d.items()]