>
>
> But we're not talking about *dict*, we're talking about dict.items which
> returns a set-like object:
>
> py> from collections.abc import Set
> py> isinstance({}.items(), Set)
> True
>
> So dict.items isn't subscriptable because it's an unordered set, not a
> sequence.
Or is it a set because it can’t be indexed? If I have the history right,
dict.items was first implemented with the “old” dict implementation, which
did not preserve order, but did provide O(1) access, so making the dict
views set-like was easy, and making them Sequences was impossible.
But now dicts do preserve order, and so making the dict views sequence-like
IS possible, and can be done efficiently—so why not?
But if a simple indexable dict is all you need, try writing a subclass.
I don’t think it’s possible to make that efficient without access to the
dict internals.
-CHB
--
Christopher Barker, PhD
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/XQPFI3CR46XN2XZHV2KJ2J5OUB7EORKC/
Code of Conduct: http://python.org/psf/codeofconduct/