Delete a key and value from an OrderedDict
Yes, you can use del: del dct[key] Below is a demonstration: >>> from collections import OrderedDict >>> dct = OrderedDict() >>> dct[‘a’] = 1 >>> dct[‘b’] = 2 >>> dct[‘c’] = 3 >>> dct OrderedDict([(‘a’, 1), (‘b’, 2), (‘c’, 3)]) >>> del dct[‘b’] >>> dct OrderedDict([(‘a’, 1), (‘c’, 3)]) >>> In fact, you should always … Read more