On Sat, Aug 1, 2020 at 10:19 AM Wes Turner firstname.lastname@example.org wrote:
We should be reading the source: https://github.com/python/cpython/blob/master/Objects/dictobject.c
AFAIU, direct subscripting / addressing was not a use case in the design phase of the current dict?
Could a __getitem__(slice_or_int_index) be implemented which just skips over the NULLs? Or would that be no faster than or exactly what islice does when next()'ing through?
There are two major points to optimize.
* Iterating over `next(islice(dict.items(), n, n+1))` will produce n temporary tuples. * (CPython implementation detail) dict can detect if there is no hole. index access is O(1) if there is no hole.