Title: `dict` items views have set like operations even when the values are not hashable. · Issue #111622 · python/cpython · GitHub
Open Graph Title: `dict` items views have set like operations even when the values are not hashable. · Issue #111622 · python/cpython
X Title: `dict` items views have set like operations even when the values are not hashable. · Issue #111622 · python/cpython
Description: Documentation Keys views are set-like since their entries are unique and :term: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 ...
Open Graph Description: Documentation Keys views are set-like since their entries are unique and :term:hashable. If all values are hashable, so that (key, value) pairs are unique and hashable, then the items view is also ...
X Description: Documentation Keys views are set-like since their entries are unique and :term:hashable. If all values are hashable, so that (key, value) pairs are unique and hashable, then the items view is also ...
Opengraph URL: https://github.com/python/cpython/issues/111622
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`dict` items views have set like operations even when the values are not hashable.","articleBody":"# Documentation\r\n\r\n\r\n\u003e Keys views are set-like since their entries are unique and [:term:`hashable`](https://github.com/python/cpython/blob/main/Doc/library/stdtypes.rst#id650). 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 [:class:`collections.abc.Set`](https://github.com/python/cpython/blob/main/Doc/library/stdtypes.rst#id652) are available (for example, ==, \u003c, or ^). While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input.\r\n\r\n\r\n```\r\n\u003e {1:2, 3:4}.items() \u003e= {1:2}.items()\r\nTrue\r\n\u003e {1:[2], 3:4}.items() \u003e= {1:[2]}.items()\r\nTrue\r\n\u003e set({1:[2], 3:4}.items())\r\nTypeError: unhashable type: 'list'\r\n```\r\n\r\nIt seems like this documentation is not accurate. `dict.items()` does have set operations even when the values are not hashable. \r\n\r\nSee also: https://stackoverflow.com/questions/77399592/set-like-behaviour-of-dict-items-for-non-hashable-values\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-112051\n* gh-112052\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/EvanTheB","@type":"Person","name":"EvanTheB"},"datePublished":"2023-11-01T22:32:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/111622/cpython/issues/111622"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4c8307df-8710-4c37-b9b3-b8245e348c7f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B774:2D4000:124570D:1953F8C:696A3D53 |
| html-safe-nonce | 4393ff660b70f7e5bd78e24448bc97dce381cd169af2e539aa462837d9b7cd04 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzc0OjJENDAwMDoxMjQ1NzBEOjE5NTNGOEM6Njk2QTNENTMiLCJ2aXNpdG9yX2lkIjoiMzg4NjkzNDYyODU3NTYyNDUzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e0532b61b90646c79290e793c24ce4a88bbd2648d33371e1c320215be784918b |
| hovercard-subject-tag | issue:1973206187 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/111622/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7dfa1527a0b30fbf0fc99241782b845f4a32224dd65a5b42d201dc078624d257/python/cpython/issues/111622 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7dfa1527a0b30fbf0fc99241782b845f4a32224dd65a5b42d201dc078624d257/python/cpython/issues/111622 |
| og:image:alt | Documentation Keys views are set-like since their entries are unique and :term:hashable. If all values are hashable, so that (key, value) pairs are unique and hashable, then the items view is also ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EvanTheB |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 13581a31d51edf4a3aca179e10890a4d4f9b6d76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width