Pop out element in a Python dictionary
Return and remove element from dictionary
The pop
method gets the value for corresponding
key and removes the key value pair from the
dictionary.
pop
method has the following syntax.
adict.pop(k [, default])
Returns adict[k]
if k
in adict
(and removes k
); else, returns default.
d = {'x': 1, 'y': 2}
print d.pop('x')
print d
The code above generates the following result.