Delete a key and value from an OrderedDict
54,342
You can use pop, popitem removes the last by default:
d = OrderedDict([(1,2),(3,4)])
d.pop(your_key)
Author by
Acoop
I am #SOreadytohelp (And I would really like a t-shirt!)
Updated on November 27, 2020Comments
-
Acoop over 3 years
I am trying to remove a key and value from an
OrderedDict
but when I use:dictionary.popitem(key)
it removes the last key and value even when a different key is supplied. Is it possible to remove a key in the middle if the dictionary?