Add Prefix to Each Key Name in Dictionary - Python Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Adding a prefix to each key in a dictionary is a common task when manipulating or organizing data. For example, we might want to indicate the source of the keys or make them more descriptive. Let's explore multiple methods to achieve this in Python.Using Dictionary ComprehensionWe can use dictionary comprehension to efficiently add a prefix to each key in the dictionary. Python # Initialize a dictionary a = {"name": "Nikki", "age": 25, "city": "New York"} # Add prefix to each key b = {f"prefix_{k}": v for k, v in a.items()} # Print the updated dictionary print(b) Output{'prefix_name': 'Nikki', 'prefix_age': 25, 'prefix_city': 'New York'} Explanation:The dictionary comprehension loops over the key-value pairs using a.items().For each key k, the prefix "prefix_" is added using an f-string.The result is a new dictionary with updated keys and the original values.Let's explore some more ways and see how we can add prefix to each key name in dictionary.Using map() for keysmap() function can be used with a lambda function to apply a transformation to the keys. Python # Initialize a dictionary a = {"name": "Nikki", "age": 25, "city": "New York"} # Add prefix to each key b = dict(map(lambda x: (f"prefix_{x[0]}", x[1]), a.items())) # Print the updated dictionary print(b) Output{'prefix_name': 'Nikki', 'prefix_age': 25, 'prefix_city': 'New York'} Explanation:map() function applies the lambda function to each key-value pair in a.items().lambda function modifies the key by adding the prefix while keeping the value unchanged.dict() function is used to convert the mapped items back into a dictionary.Using for LoopA traditional for loop can also be used to create a new dictionary with prefixed keys. Python # Initialize a dictionary a = {"name": "Nikki", "age": 25, "city": "New York"} # Initialize an empty dictionary b = {} # Add prefix to each key for k, v in a.items(): b[f"prefix_{k}"] = v # Print the updated dictionary print(b) Output{'prefix_name': 'Nikki', 'prefix_age': 25, 'prefix_city': 'New York'} Explanation:An empty dictionary b is initialized to store the new key-value pairs.The for loop iterates over a.items(), and the prefix is added to each key using an f-string.Each updated key-value pair is added to the new dictionary. Create Quiz Comment M manjeet_04 Follow 0 Improve M manjeet_04 Follow 0 Improve Article Tags : Python Python Programs Python dictionary-programs Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like