Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove more than one key from Python dict

Is there any efficient shortcut method to delete more than one key at a time from a python dictionary?

For instance;

x = {'a': 5, 'b': 2, 'c': 3}
x.pop('a', 'b')
print x
{'c': 3}
like image 852
Ozgur Vatansever Avatar asked Dec 09 '11 16:12

Ozgur Vatansever


1 Answers

Use the del statement:

x = {'a': 5, 'b': 2, 'c': 3}
del x['a'], x['b']
print x
{'c': 3}
like image 150
vartec Avatar answered Nov 02 '22 00:11

vartec