
July 1, 2020
7:32 a.m.
On Wed, Jul 01, 2020 at 01:07:34PM +0200, Dominik Vilsmeier wrote:
What is the reason for `dict.items` to return a set-like object?
This is the third time I've linked to the PEP: https://www.python.org/dev/peps/pep-3106/ More than that, you would have to ask Guido, or the designers of the Java framework that inspired it.
>>> from collections.abc import Set >>> isinstance({'a': []}.items(), Set) True
`dict.items` could provide all of its "standard" behavior (like membership testing, reversing, etc) without being set-like.
Its standard behaviour includes set-like unions and intersections, and has done for over a decade, back to 3.0 and 2.7. -- Steven