On Sat, Aug 1, 2020 at 10:19 AM Wes Turner <[email protected]> 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. -- Inada Naoki <[email protected]> _______________________________________________ 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/BL24ZADLYFMRXQXHJ3HNQQMCEDTORLZH/ Code of Conduct: http://python.org/psf/codeofconduct/
