If you need custom sort-orders and slicing for dicts, I've implemented a b-tree backed mapping that can do just that a couple weeks ago - you are welcome to use it: https://github.com/jsbueno/extradict/blob/80817e75eabdde5583aa828c04beae6a20... (just "pip install extradict" ) It does not support numeric indexing, though - you'd need a pair of TreeDict's to do it: ```py from extradict import TreeDict a = TreeDict(('abc', 'bar'), ('def', 'foo'), ('ghi', 'baz'), ('jkl', 'bam')) a["a":"f"] out: ['bar', 'foo'] b = TreeDict(*((i, key) for i, key in enumerate(a))) # Using numeric keys for range from 'a' keys: [(key, a[key]) for key in b[1:4]] out: [('def', 'foo'), ('ghi', 'baz')] ``` On Mon, 29 Jun 2020 at 08:59, Hans Ginzel <hans@matfyz.cz> wrote:
Thank you.
On Fri, Jun 26, 2020 at 02:50:22PM -0300, Joao S. O. Bueno wrote:
On Fri, 26 Jun 2020 at 14:30, Hans Ginzel <hans@matfyz.cz> wrote:
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. …
These are odd requirements.
No - Python dictionaries are ordered, by order of insertion only, but one can't generally do any manipulation by the numeric index of a dictionary entry - and it will stay that way.
That is fully corret to respect the _insertion_ order.
If you need such an hybrid data structure, you could just have a list of tuples as data structure, and use collections.abc.MutableMapping to provide a dict-like interface to it (an index for better than linear search).
I could create such a data structure if you want,
Thank you, I will write it myself. H.