Python Dictionary Remove Element by Value Example

By Hardik Savani October 30, 2023 Category : Python

Hey,

In this article, we will cover python dictionary remove element by value. In this article, we will implement a python dictionary remove item by value. This post will give you a simple example of python dictionary delete item by value. we will help you to give an example of python remove dictionary item by value. Here, Create a basic example of python delete dictionary item by value.

There are several ways to remove element by value from a dictionary in python. i will give you simple example using value in python.

So, without further ado, let's see simple examples:

Example 1:

main.py

user = {
  "ID": 1,
  "name": "Hardik Savani",
  "email": "hardik@gmail.com"
}
  
# Remove Item from dictionary
user = {key:val for key, val in user.items() if val != "hardik@gmail.com"}
  
print(user)

Output:

{
 'ID': 1,
 'name': 'Hardik Savani'
}

I hope it can help you...

Tags :
Shares