Answers for "delete key in dictionary"

13

delete key in dictionary

>>> # initialise a dictionary with the keys “city”, “name”, “food”
>>> person1_information = {'city': 'San Francisco', 'name': 'Sam', "food": "shrimps"}

>>> # delete the key, value pair with the key “food”
>>> del person1_information["food"]

>>> # print the present personal1_information. Note that the key, value pair “food”: “shrimps” is not there anymore.
>>> print(person1_information)
{'city': 'San Francisco', 'name': 'Sam'}
Posted by: Guest on December-09-2019
3

delete key from python dictionary

dictionary.pop(key)
Posted by: Guest on January-19-2021

Code answers related to "delete key in dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language