Python - Remove Dictionary Key Words Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report We are given a dictionary we need to remove the dictionary key words. For example we are given a dictionary d = {'a': 1, 'b': 2} we need to remove the dictionary key words so that the output becomes {'b': 2} . We can use method like del , pop and other methods to do it.Using del keyworddel keyword is used to remove a specific key-value pair from a dictionary by specifying the key. If the key exists, it will be deleted; otherwise, it raises a KeyError. Python d = {'a': 1, 'b': 2} # Remove the key-value pair where the key is 'a' from the dictionary del d['a'] print(d) Output{'b': 2} Explanation:Dictionary d is initialized with two key-value pairs: 'a': 1 and 'b': 2.del keyword is used to remove the key-value pair with key 'a', and the modified dictionary {'b': 2} is printed.Using pop() methodpop() method removes and returns the value associated with a specified key in a dictionary. If the key is not found, it raises a KeyError unless a default value is provided. Python d = {'a': 1, 'b': 2} # Remove the key-value pair where the key is 'a' and return its value d.pop('a') print(d) Output{'b': 2} Explanation:pop('a') method removes key-value pair where the key is 'a' from the dictionary d and returns its value (1 in this case).Modified dictionary {'b': 2} is then printed as it no longer contains key 'a'Using popitem()popitem() method removes and returns the last key-value pair from a dictionary as a tuple. If the dictionary is empty, it raises a KeyError. Python d = {'a': 1, 'b': 2} # Removes the last key-value pair ('b': 2) from the dictionary d.popitem() print(d) Output{'a': 1} Explanation:popitem() method removes and returns the last key-value pair ('b': 2) from the dictionary d.modified dictionary {'a': 1} is printed, which now only contains the key 'a'Using Dictionary ComprehensionDictionary comprehension allows you to create a new dictionary by applying an expression to each key-value pair of an existing dictionary. Python d = {'a': 1, 'b': 2} # Use dictionary comprehension to create a new dictionary excluding the key 'a' d = {key: value for key, value in d.items() if key != 'a'} print(d) Output{'b': 2} Explanation:Dictionary comprehension iterates over the original dictionary d and creates a new dictionary, excluding the key 'a'.Modified dictionary, which now only contains the key 'b': 2, is printed. Create Quiz Comment M manjeet_04 Follow 4 Improve M manjeet_04 Follow 4 Improve Article Tags : Python Python dictionary-programs Python string-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