On Mon, Jun 29, 2020 at 11:02:54PM -0700, Christopher Barker wrote:

> > 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.

No, making them set-like was intentional.

The history goes something like this:

In Python 1, and early Python 2, dict.keys(), .values() and .items() 
each returned lists. Some time by 2.4 (possibly earlier) dicts grew 
additional methods returning iterators:

    dict.iterkeys() .itervalues() .iteritems()

As part of the migration from Python 2 to 3, it was planned to change 
them to set-like views:

https://www.python.org/dev/peps/pep-3106/

so as an aid to migration, these set-like views were added to 2.7:

    dict.viewkeys() .viewvalues() .viewitems()

and finally in 3.x, the list and iterator versions were all dropped and 
the views were renamed.

So there was already a sequence version of items etc, and the set-like 
views were explicitly intended to be set-like.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XT4T7OIEAY7YQZR6K2ODOQZRXT24YIXY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to