how to remove a value from dictionary in python code example
Example 1: remove element from dictionary python
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
Example 2: delete a key value pair from a dictionary in python
mydict = {'score1': 41, 'score2': 23, 'score3': 45}
del mydict['score2']
print(mydict)
{'score1': 41, 'score3': 45}
Example 3: how to remove dictionary entry in python
del dic[key]
Example 4: remove elements from dictionary python
squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
print(squares.pop(4))