How to Remove Element by Value from Python Dictionary?

31-Jan-2023

.

Admin

How to Remove Element by Value from Python Dictionary?

Hi Dev,

Today our leading topic is how to remove element by value from python dictionary. I explained simply about python delete dictionary element by value. we will help you to give example of python delete dictionary item by value. step by step explain python remove 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.

Example :


main.py

user = {

"ID": 1,

"name": "Piyush Kamani",

"email": "piyush@gmail.com"

}

# Remove Item from dictionary

user = {key:val for key, val in user.items() if val != "piyush@gmail.com"}

print(user)

Output:

{

'ID': 1,

'name': 'Piyush Kamani'

}

#Python