For a regular dict, you can use:

mydict[k_new] = mydict.pop(k_old)

This will move the item to the end of the dict, unless k_new was already existing in which case it will overwrite the value in-place.

For a Python 3.7+ dict where you additionally want to preserve the ordering, the simplest is to rebuild an entirely new instance. For example, renaming key 2 to 'two':

>>> d = {0:0, 1:1, 2:2, 3:3}
>>> {"two" if k == 2 else k:v for k,v in d.items()}
{0: 0, 1: 1, 'two': 2, 3: 3}

The same is true for an OrderedDict, where you can't use dict comprehension syntax, but you can use a generator expression:

OrderedDict((k_new if k == k_old else k, v) for k, v in od.items())

Modifying the key itself, as the question asks for, is impractical because keys are hashable which usually implies they're immutable and can't be modified.

Answer from wim on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-change-the-name-of-a-key-in-dictionary
How to Change the name of a key in dictionary? - GeeksforGeeks
July 23, 2025 - def rename_key_nested(dictionary, old_key, new_key): for key in list(dictionary.keys()): if isinstance(dictionary[key], dict): rename_key_nested(dictionary[key], old_key, new_key) if key == old_key: dictionary[new_key] = dictionary.pop(old_key) # Original nested dictionary nested_dict = { 'level1': { 'old_key': 'value', 'level2': { 'old_key': 'value2' } } } # Rename 'old_key' to 'new_key' in nested dictionary rename_key_nested(nested_dict, 'old_key', 'new_key') print(nested_dict) ... Changing the name of a key in a dictionary is a common task in Python programming.
Discussions

How to change the name of a key in a dictionary, ideally without deleting it?
Removing the old and adding new key-value pair is the only option. And what do you mean by "I don't really want to have to keep updating it"? If value1 is passed by value, you'll have to update it anyway and if it's passed by reference, changing the key doesn't matter because your new key will point to the same object. More on reddit.com
🌐 r/godot
8
2
November 20, 2021
How to change a dicts value for one of the keys?
list = {} Triggered. Sorry, mostly kidding, but list is a type, and definitely should not be used as the variable name for a dict. Also, using a try/except on EOFError for breaking out of your while loop is really weird. Are you trying to mess with people? =) Again, kidding, lol. I basically want to get the value of one key in my dict and add to it, but not to any of the other keys. I have searched all over the internet and can not find or just do not know how to word it to find a solution. What are you actually expecting to do? As written, your code doesn't attempt to change any value, and doing so is very simple. Let's say one of your inputs is "apple". This creates the following key/value pair in your dict: {"apple": 1}. To change this value to, say, 5, you'd simply do this: my_dict["apple"] = 5 That changes the value from 1 to 5. Now, if you want to add to it in the sense of a number, you can do this instead: my_dict["apple"] += 5 This will add 5 to the original value of 1, so your new dict will be this: {"apple": 1} Finally, if you mean "add" as in "add additional values", you need to convert your value into a type that allows for multiple values. The most common is to use a list like this: my_dict = {} dict_key = input() my_dict[dict_key] = [1] my_dict[dict_key].append(5) print(my_dict) # input: test # output: {'test': [1, 5]} If you gave some more details about what you are trying to do we can probably help more. Does that make sense? More on reddit.com
🌐 r/learnpython
23
4
May 13, 2024
Renaming duplicate keys in a dictionary
You need to reset add_one when you find a new name. More on reddit.com
🌐 r/learnpython
8
4
September 11, 2024
How do I map the keys of a dictionary to the columns of a pandas dataframe?

Keep this paradigm in your head: dataframes are meant to be instantiated from a data source, they aren't meant to be created as a blank sheet and 'filled in' later on. So also in this case: don't build a dataframe upfront, instead create the dataframe using the dict as the basis for its data. From Create a Pandas DataFrame from List of Dicts:

cols = ['timestamp', 'name', 'adress', 'phone', 'website', 'rating', 'number_of_ratings', 'type']
df = pd.DataFrame(multidict, columns=cols)
More on reddit.com
🌐 r/learnpython
5
7
January 12, 2020
🌐
Note.nkmk.me
note.nkmk.me › home › python
Change a Key Name in a Dictionary in Python | note.nkmk.me
August 21, 2023 - Merge multiple dictionaries and add items to a dictionary in Python · Since dict does not provide a method to directly rename a key, you need to add a new item with the new key and original value, then remove the old item.
🌐
GitHub
gist.github.com › JokerMartini › c3a38069020480727e5e
Python: Renames recursively every key in a dictionary to lowercase. · GitHub
def dict_rename_key(iterable, old_key, new_key): """ dict_rename_key method Args: iterable (dict): [description] old_key (string): [description] new_key (string): [description] Returns: dict: [description] Examples: >>> data = {'MIKE': 'test', 'JOHN': 'doe'} >>> data_modified = dict_rename_key(data, 'MIKE', 'mike') >>> assert 'mike' in data_modified """ if isinstance(iterable, dict): for key in list(iterable.keys()): if key == old_key: iterable[new_key] = iterable.pop(key) return iterable
🌐
W3Schools
w3schools.com › Python › python_dictionaries_change.asp
Python - Change Dictionary Items
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["year"] = 2018 Try it Yourself » · The update() method will update the dictionary with the items from the given argument. The argument must be a dictionary, or an iterable object with key:value pairs.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-change-keys-in-dictionary
Ways to change keys in dictionary - Python - GeeksforGeeks
May 13, 2025 - The key 'Amit' is replaced with 'Suraj'. The original dictionary my_dict is deleted and replaced by new_dict.
🌐
YouTube
youtube.com › codeflare
python dict rename key - YouTube
Download this code from https://codegive.com Title: Renaming Keys in a Python Dictionary: A Step-by-Step TutorialIntroduction:In Python, dictionaries are wid...
Published   December 20, 2023
Views   1
🌐
Pybites Platform
pybitesplatform.com › bites › rename-keys
Rename keys
Some of the dictionary keys start with @ symbols and the Accounting Department will have none of this. Complete the rename_keys() function to remove the @ character from the beginning of the dictionary key names(Warning: Not all the dictionary ...
🌐
Elastic
elastic.co › elastic docs › reference › ingestion tools › elastic integrations › azure › azure activity logs opentelemetry assets
Azure Activity Logs OpenTelemetry Assets | Elastic integrations
Azure Activity Logs provide a platform-level audit trail for Azure Resource Manager control plane operations, including resource creation, modification,...
🌐
W3Schools
w3schools.com › python › python_ref_dictionary.asp
Python Dictionary Methods
Python has a set of built-in methods that you can use on dictionaries.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-change-keys-case-in-dictionary
Python - Change Keys Case in Dictionary - GeeksforGeeks
May 10, 2023 - If it is, call the change_keys_case() function recursively on the nested dictionary. Return the modified dictionary. ... # Python3 code to demonstrate working of # Change Keys Case in Dictionary # Using map() + lambda + recursion # helper function ...
🌐
Elastic
elastic.co › elastic docs › reference › ingestion tools › elastic integrations › cassandra opentelemetry assets
Cassandra OpenTelemetry Assets | Elastic integrations
receivers: jmx/cassandra: jar_path: <JMX_JAR_PATH> endpoint: <CASSANDRA_JMX_ENDPOINT> target_system: cassandra collection_interval: 10s processors: resource/dataset: attributes: - key: data_stream.dataset value: cassandra action: upsert batch: timeout: 10s send_batch_size: 1024 exporters: elasticsearch/otel: endpoint: <ES_ENDPOINT> api_key: <ES_API_KEY> mapping: mode: otel service: pipelines: metrics: receivers: [jmx/cassandra] processors: [resource/dataset, batch] exporters: [elasticsearch/otel]
🌐
Medium
medium.com › synthetic-futures › i-dropped-20-month-on-claude-code-for-a-free-chinese-model-heres-what-broke-and-what-didn-t-016499ddc7a4
Medium
April 4, 2026 - I Dropped $20/Month on Claude Code for a Free Chinese Model — Here’s What Broke (And What Didn’t) Alibaba’s Qwen 3.6-Plus just went free on OpenRouter. I gave it a real workload. The results …
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_csv.html
pandas.read_csv — pandas 3.0.4 documentation
The C and pyarrow engines are faster, while the python engine is currently more feature-complete. Multithreading is currently only supported by the pyarrow engine. Some features of the “pyarrow” engine are unsupported or may not work correctly. ... Functions for converting values in specified columns. Keys ...
🌐
Pandas
pandas.pydata.org › docs › reference › frame.html
DataFrame — pandas 3.0.4 documentation
DataFrame.attrs is a dictionary for storing global metadata for this DataFrame.
🌐
GitHub
github.com › pyrevitlabs › pyRevit › releases
Releases · pyrevitlabs/pyRevit
4 weeks ago - WPFPanel parity: Extracted _WPFMixin shared by WPFWindow and WPFPanel; panels now support load_xaml() with locale and resource dictionaries. (#3177, #3146) IFC export helper: ifc.py extended with config loader, export-options builder (decimal-separator workaround), and single-call IFCExporter. (#3147) UpdaterListener: Now triggers on element addition and deletion, not just modification. (#3139) Logging level fix: pyRevit logging enum correctly translated to Python scale -- no more unwanted console on startup. (#3207) Match, Pick, Selection, ViewRange, Keynote, SectionBox, ColorSplasher, ReNumber, Measure
Author   pyrevitlabs
🌐
GitHub
github.com › salesforce › agentscript
GitHub - salesforce/agentscript: An open, schema-driven language for configuring agent orchestration systems · GitHub
1 week ago - Dialect-agnostic LSP core. All providers (diagnostics, hover, completions, definition, references, rename, symbols, code actions, semantic tokens) live here.
Starred by 258 users
Forked by 51 users
Languages   TypeScript 96.6% | JavaScript 1.6% | MDX 1.0% | CSS 0.3% | C 0.2% | Tree-sitter Query 0.1%