zjm1126 zjm1126 - 3 years ago 217
Python Question

Best way to pop many elements from a Python dict

This is my code:

a = dict(aa='aaaa', bb='bbbbb', cc='ccccc', ...)
print(a.pop(['cc', ...]))


but this raises an error.
What is the best simple way to pop many elements from a python dictionary?

Answer Source

How about the simple:

for e in ['cc', 'dd',...]: 
  a.pop(e)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download