It sounds like you're asking if the iteration order can be changed to be something other than the original insertion order, or if you can cause a new key-value pair to be added somewhere other than the end. I wonder if you can achieve the desired outcome without a change to the language.
At any time, you can take the items in the dictionary, sort them however you'd like, and then put them into a new dictionary. sorted_items = sorted(my_dict.items(), key=lambda x: x[0].upper()) sorted_dict = dict(sorted_items) There's probably a more elegant way to do the first line. But you could do this before you perform the operation wherein you need the dict to be ordered a certain way. Steele On Fri, Jun 26, 2020 at 1:30 PM Hans Ginzel <h...@matfyz.cz> wrote: > Date: Fri, 26 Jun 2020 18:47:44 +0200 > From: Hans Ginzel <h...@matfyz.cz> > To: Hans Ginzel <h...@artax.karlin.mff.cuni.cz> > Subject: Access (ordered) dict by index; insert slice > > Hello, > > thank you for making dict ordered. > Is it planned to access key,value pair(s) by index? See > https://stackoverflow.com/a/44687752/2556118 for example. Both for > reading and (re)writing? > Is it planned to insert pair(s) on exact index? Or generally to slice? See > splice() in Perl, https://perldoc.perl.org/functions/splice.html. > > Use case: Represent database table metadata (columns). It is useful as to > access columns both by name and by index as to insert column on specific > position, https://dev.mysql.com/doc/refman/8.0/en/alter-table.html, > “ALTER TABLE ADD COLUMN [FIRST |AFTER col]” (consider default order or > table storage size optimisation by aligning). > > Thank you in advance, > Hans > PS1: Named tuples cannot be used, are immutable. > PS2: See > https://metacpan.org/pod/perlref#Pseudo-hashes:-Using-an-array-as-a-hash > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@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/S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@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/2IXSBCDXKI3JIX5PNU7ELCVNBPIDWPPE/ Code of Conduct: http://python.org/psf/codeofconduct/