
On Thu, Jul 30, 2020, 3:37 PM Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
On Thu, 30 Jul 2020 at 19:24, Steven D'Aprano <steve@pearwood.info> wrote:
You can't insert a key in a specific position. If I have this dict:
mydict = {'a': 1, 'c': 3, 'd': 4, 'e': 5}
I can't insert 'b':2 between keys 'a' and 'c', except by creating a new dict.
Not sure about this. In C code, dicts are a hashtable and an array of items. In theory, nothing prevents you from inserting a new key in a specific position of the key array instead of at the end.
Nothing but the cost of shifting successive elements by 1 and sometimes copying the entire array to a new, larger array. Would these be the *non-mutating* methods desired of insertion-ordered dicts? .iloc[sli:ce] .iloc[int] .iloc[[list,]] .iloc[callable] .iloc[bitmask] .index(key) _______________________________________________
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PX6OBI... Code of Conduct: http://python.org/psf/codeofconduct/