Answers for "how to remove a key value pair from a dict python"

4

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}
Posted by: Guest on May-14-2020
2

python remove key from dict

my_dict.pop('key', None)
Posted by: Guest on September-03-2020

Code answers related to "how to remove a key value pair from a dict python"

Python Answers by Framework

Browse Popular Code Answers by Language