pythonpython-3.xordereddict

(Im)mutability of OrderedDict


Is Python's OrderedDict data structure a mutable collection?

The documentation does not say anything about it, and after a quick search on the web, I have not found any answer yet.


Solution

  • The documentation does not say anything about it, and after a quick search on the web, I have not found any answer yet.

    When in doubt regarding mutability of class you might run following test

    from collections import OrderedDict
    from collections.abc import MutableSequence, MutableSet, MutableMapping
    print(issubclass(OrderedDict,(MutableSequence,MutableSet,MutableMapping)))
    

    output

    True
    

    See Collections Abstract Base Classes in collections.abc docs for other things which can be checked this way.