[Python-Dev] The current dict is not an "OrderedDict"
Serhiy Storchaka
storchaka at gmail.com
Tue Nov 7 10:37:15 EST 2017
07.11.17 16:56, Steven D'Aprano пише:
> To clarify: if we start with an empty dict, add keys A...D, delete B,
> then add E...H, we could expect:
>
> {A: 1}
> {A: 1, B: 2}
> {A: 1, B: 2, C: 3}
> {A: 1, B: 2, C: 3, D: 4}
> {D: 4, A: 1, C: 3} # some arbitrary reordering
> {D: 4, A: 1, C: 3, E: 5}
> {D: 4, A: 1, C: 3, E: 5, F: 6}
> {D: 4, A: 1, C: 3, E: 5, F: 6, G: 7}
> {D: 4, A: 1, C: 3, E: 5, F: 6, G: 7, H: 8}
Rather
{A: 1, D: 4, C: 3} # move the last item in place of removed
{A: 1, D: 4, C: 3, E: 5}
{A: 1, D: 4, C: 3, E: 5, F: 6}
{A: 1, D: 4, C: 3, E: 5, F: 6, G: 7}
{A: 1, D: 4, C: 3, E: 5, F: 6, G: 7, H: 8}
or
{A: 1, C: 3, D: 4}
{A: 1, E: 5, C: 3, D: 4} # place the new item in place of removed
{A: 1, E: 5, C: 3, D: 4, F: 6}
{A: 1, E: 5, C: 3, D: 4, F: 6, G: 7}
{A: 1, E: 5, C: 3, D: 4, F: 6, G: 7, H: 8}
or
{A: 1, C: 3, D: 4}
{A: 1, C: 3, D: 4, E: 5} # add new items at end until fill the array
{A: 1, F: 6, C: 3, D: 4, E: 5} # and fill holes after that
{A: 1, F: 6, C: 3, D: 4, E: 5, G: 7} # reallocate the array
{A: 1, F: 6, C: 3, D: 4, E: 5, G: 7, H: 8}
These scenarios are more probably.
More information about the Python-Dev
mailing list