[issue20190] dict() in dict(foo='bar').keys() raises
Raymond Hettinger
report at bugs.python.org
Fri Jan 10 03:38:36 CET 2014
Raymond Hettinger added the comment:
> I think the problem is that the API of dict.keys() is surprising.
> One gets back something that behaves like a list, the name 'keys'
> suggests that it is a list and for lists there is no requirement
> that their containing items need to be hasheable.
The keys() method returns a view with set-like behavior (it supports union, intersection, difference, fast membership testing using hashed lookups, and iteration).
Guido modeled this behavior from a well established API in Java.
FWIW, it is hard for us to do anything about comments like "I was surprised ..." The language behaviors are documented but that doesn't help if the docs aren't read. If you expected a list-like object but received a set-like object, then you would get surprised. There is not much that can be done about that.
----------
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20190>
_______________________________________
More information about the Python-bugs-list
mailing list