Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects

> Keys views are set-like since their entries are unique and hashable. If all 
> values are hashable, so that (key, value) pairs are unique and hashable, then 
> the items view is also set-like. (Values views are not treated as set-like 
> since the entries are generally not unique.) For set-like views, all of the 
> operations defined for the abstract base class collections.abc.Set are 
> available (for example, ==, <, or ^).

In Python 2 keys() and values() return a list where __eq__ is implemented. In 
Python 3 view objects are returned. This can be seen in Python 2 also using 
viewkeys and viewvalues where viewvalues() is False. So this is not a bug but I 
am not sure if docs can be improved to clarify this further.


$ python2
Python 2.7.14 (default, Mar 12 2018, 13:54:56)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = {'a': 1}
>>> b = {'a': 1}
>>> a.viewkeys() == b.viewkeys()
True
>>> a.viewvalues() == b.viewvalues()
False
>>> a.values() == b.values()
True

----------
nosy: +rhettinger, xtreak

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to