Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] The current dict is not an "OrderedDict"

Random832random832 at fastmail.com
Tue Nov 7 23:38:23 EST 2017


On Tue, Nov 7, 2017, at 09:56, Steven D'Aprano wrote:> Don't let the perfect be the enemy of the good.>> For many applications, keys are never removed from the dict, so this> doesn't matter. If you never delete a key, then the remaining keys will> never be reordered.>> I think that Nick's intent was not to say that after a single deletion,> the ordering guarantee goes away "forever", but that a deletion may be> permitted to reorder the keys, after which further additions will honour> insertion order. At least, that's how I interpret him.Honestly, I think the more intuitive way would be the "other way around"- deletions don't themselves change the order, but they do causesubsequent insertions to be allowed to insert at places other than theend.Does the implementation in CPython have this property?One way I have seen this done is that the items themselves live in anarray, and each new item is always inserted in the first empty slot inthe array (empty slots form a freelist). The hash buckets containindices into the array.


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp