0 votes
1 view
in Python by (40.4k points)

When deleting a key from a dictionary, I use:

if 'key' in myDict: 

del myDict['key']

Is there a one-line way of doing this?

1 Answer

0 votes
by (92.9k points)

To remove a key from a dictionary, you can use the two-argument form of dict.pop():

my_dict.pop('key', None)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...