On 7/24/2019 1:30 PM, Brett Cannon wrote:
Serhiy Storchaka wrote:
o you propose? What is the use case for it?
If you want to compare dict value views as ordered sequences, it can be
surprised that d1.values() != d2.values() when d1 == d2. It will
be
inconsistent with orderless comparison of keys() and items(). If
you
want to compare them as unordered sequences, the computation complexity
of the operation will be quadratic.
Note also, that while in Python 2 always d.values() == d.values(), it
is possible that d1.keys() != d2.keys() and d1.values() !=
d2.values() when d1 == d2. Python 3 is more consistent.
When I saw this I thought, "it should be like `set(d1.values()) ==
set(d2.values())`", but has been pointed out there's no guarantee that
all values will be hashable. After that I have no expectation since
order isn't guaranteed.
I think this is one of those cases where it's superficially surprising
when you don't think about all the ramifications, but once you
understand the complexity of the problem then it becomes more clear
that it isn't straight-forward.
To me a doc update for dict.values() stating that the iterator can't
be compared and a brief mention as to why would be the best solution
for this.
(I hope my quoting is correct.)
I agree with Brett: let's just document this and not make any code changes.
If someone really has a use case, which I haven't seen, then they can
write their own comparison using constraints specific to their data:
perhaps their values are hashable, for example.
Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/C774AG3OQRG6XCZ4JKVP6UYDX6DELMQR/