Problem with OrderedDict
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed May 30 09:16:05 EDT 2018
On Wed, 30 May 2018 23:05:53 +1000, Chris Angelico wrote:
> You can always change the *values*, but not the *order* of the keys.
Okay, so far we have these operations which are allowed:
- changing a value associated with a key
and these operations which all raise RuntimeError with the "mutated"
error message:
- changing the position of a key;
- deleting a key (using either del or popitem);
- adding a new key;
- deleting a key and adding it back again;
- deleting a key and adding a new key.
This is the only thing I've found so far that gives the "changed size"
error message:
- clearing the dictionary with d.clear()
Phew! I was starting to think Frank was imagining it, and that the
"changed size" test was dead code :-)
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list