Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce0506c

Browse files
committed
rephrase dict view docs
1 parent 276c371 commit ce0506c

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,7 @@ Dictionary view objects
18811881
The objects returned by :meth:`dict.keys`, :meth:`dict.values` and
18821882
:meth:`dict.items` are *view objects*. They provide a dynamic view on the
18831883
dictionary's entries, which means that when the dictionary changes, the view
1884-
reflects these changes. The keys and items views have a set-like character
1885-
since their entries
1884+
reflects these changes.
18861885

18871886
Dictionary views can be iterated over to yield their respective data, and
18881887
support membership tests:
@@ -1910,8 +1909,11 @@ support membership tests:
19101909
items (in the latter case, *x* should be a ``(key, value)`` tuple).
19111910

19121911

1913-
The keys and items views also provide set-like operations ("other" here refers
1914-
to another dictionary view or a set):
1912+
Keys views are set-like since their entries are unique and hashable. If all
1913+
values are hashable, so that (key, value) pairs are unique and hashable, then
1914+
the items view is also set-like. (Values views are not treated as set-like
1915+
since the entries are generally not unique.) Then these set operations are
1916+
available ("other" refers either to another view or a set):
19151917

19161918
.. describe:: dictview & other
19171919

@@ -1931,11 +1933,6 @@ to another dictionary view or a set):
19311933
Return the symmetric difference (all elements either in *dictview* or
19321934
*other*, but not in both) of the dictview and the other object as a new set.
19331935

1934-
.. warning::
1935-
1936-
Since a dictionary's values are not required to be hashable, any of these
1937-
four operations will fail if an involved dictionary contains such a value.
1938-
19391936

19401937
An example of dictionary view usage::
19411938

0 commit comments

Comments
 (0)