

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove a key from a python dictionary?
Python’s del keyword is used pretty much any object. In order to delete a particular item from dictionary, provide key clause to del statement
>>> D1 = {1: 'a', 2: 'b', 3: 'c', 'x': 1, 'y': 2, 'z': 3} >>> del D1['x'] >>> D1 {1: 'a', 2: 'b', 3: 'c', 'y': 2, 'z': 3}
Effect of removing a key-value pair can also be achieved by pop() method. The method takes key (and optionally value if more than one values are assigned to same key)
>>> D1 = {1: 'a', 2: 'b', 3: 'c', 'x': 1, 'y': 2, 'z': 3} >>> D1.pop('y') 2 >>> D1 {1: 'a', 2: 'b', 3: 'c', 'x': 1, 'z': 3}
- Related Questions & Answers
- Python - Ways to remove a key from dictionary
- How to get a value for a given key from a Python dictionary?
- How to check if a key exists in a Python dictionary?
- Java Program to remove a key from a HashMap
- How to search for the highest key from Python dictionary?
- Remove elements from a Dictionary using Javascript
- Accessing Key-value in a Python Dictionary
- How to print a value for a given key for Python dictionary?
- Remove a key from TreeMap in Java
- Add a key value pair to dictionary in Python
- Get key from value in Dictionary in Python
- Finding The Biggest Key In A Python Dictionary?
- How to update the value of a key in a dictionary in Python?
- How to check if a given key already exists in a Python dictionary?
- How to remove primary key from MongoDB?
Advertisements