here is the thread from the last time that this was brought up: https://mail.python.org/archives/list/[email protected]/thread/S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ/#S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ
It was very thoroughly discussed then. -CHB On Sun, Oct 10, 2021 at 8:33 AM Guido van Rossum <[email protected]> wrote: > You have to check the C code to be sure, but IIRC the latest dict > implementation has a dense array of the values in insert order, and the > hash table (which has gaps) contains indexes into the values array. So you > could easily index into the values array (which I believe also has the > keys) in O(1) time. > > Though what happens to the dense array when a key is deleted? It must > leave a gap there too. So, never mind, you’d have to walk through the array > counting items but not gaps, and that’s O(n). Which explains why we don’t > have such an API. But please check the C code! > > —Guido > > On Sun, Oct 10, 2021 at 07:18 Alex Waygood <[email protected]> wrote: > >> Should `dict.items()` be indexable now that dicts are ordered? I say yes. >> Why shouldn't it? >> >> >> Would there be a way to ensure that this had the same time complexity as >> indexing of sequences? If "yes", I would support this — I think it would be >> useful in some situations, and it would be more efficient than existing >> mechanisms to obtain the *n*th key from a dictionary. If (as I presume), >> the answer is "no", then I would not support this — I think it would give >> the misleading impression that obtaining the *n*th key/value from a >> dictionary is just as efficient as obtaining the *n*th item from a list >> or tuple. >> >> Best, >> Alex >> >> On 10 Oct 2021, at 05:05, Finn Mason <[email protected]> wrote: >> >> >> >> On Sat, Oct 9, 2021, 9:56 PM Steven D'Aprano <[email protected]> wrote: >> >>> [Snip...] >> >> >> Newbies won't know first() lives in itertools, and those experienced >>> enough to know it is there probably won't bother to use it. >>> >> >> A very good point. >> >> Let's get back to the original topic. Should `dict.items()` be indexable >> now that dicts are ordered? I say yes. Why shouldn't it? >> >> >> -- >> Finn Mason >> >>> _______________________________________________ >> 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/OOR2AUMA7UMHHVW7XLLUXHTNKGRXTPU4/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> >> _______________________________________________ >> 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/RHNNAZR2ZBYZFQ75VHR3FUMVY6GWDDB6/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > -- > --Guido (mobile) > _______________________________________________ > 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/BISXD643VSNQVE6RFPWGZNH5SL3GE3QE/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/2PDYYRS4P4OGTGI5GUJIOT2M4EYUU4EM/ Code of Conduct: http://python.org/psf/codeofconduct/
