On Mon, 29 Jun 2020 at 17:03, Joao S. O. Bueno <[email protected]> wrote:
> 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/80817e75eabdde5583aa828c04beae6a20d3c4f7/extradict/binary_tree_dict.py#L354 > > (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')] > > ``` > > (Meh, I was fiddling with the snippet above in thee-mail composotion and messed it - the range that is output in the listing is the corresponding to b[1:3], and the lib outputs it correctly)
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/WDPJH6GCBBFNER3U47EHF7EYLIDMNFTT/ Code of Conduct: http://python.org/psf/codeofconduct/
