@@ -4826,7 +4826,7 @@ other sequence-like behavior.
48264826
48274827There are currently two built-in set types, :class: `set ` and :class: `frozenset `.
48284828The :class: `set ` type is mutable --- the contents can be changed using methods
4829- like :meth: `add <frozenset .add> ` and :meth: `remove <frozenset.add> `.
4829+ like :meth: `~set .add ` and :meth: `~set.remove `.
48304830Since it is mutable, it has no hash value and cannot be used as
48314831either a dictionary key or as an element of another set.
48324832The :class: `frozenset ` type is immutable and :term: `hashable ` ---
@@ -4848,164 +4848,172 @@ The constructors for both classes work the same:
48484848 objects. If *iterable * is not specified, a new empty set is
48494849 returned.
48504850
4851- Sets can be created by several means:
4851+ Sets can be created by several means:
48524852
4853- * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4854- * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4855- * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
4853+ * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4854+ * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4855+ * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
48564856
4857- Instances of :class: `set ` and :class: `frozenset ` provide the following
4858- operations:
4857+ Instances of :class: `set ` and :class: `frozenset ` provide the following
4858+ operations:
48594859
4860- .. describe :: len(s)
4860+ .. describe :: len(s)
48614861
4862- Return the number of elements in set *s * (cardinality of *s *).
4862+ Return the number of elements in set *s * (cardinality of *s *).
48634863
4864- .. describe :: x in s
4864+ .. describe :: x in s
48654865
4866- Test *x * for membership in *s *.
4866+ Test *x * for membership in *s *.
48674867
4868- .. describe :: x not in s
4868+ .. describe :: x not in s
48694869
4870- Test *x * for non-membership in *s *.
4870+ Test *x * for non-membership in *s *.
48714871
4872- .. method :: isdisjoint(other, /)
4872+ .. method :: frozenset.isdisjoint(other, /)
4873+ set.isdisjoint(other, /)
48734874
4874- Return ``True `` if the set has no elements in common with *other *. Sets are
4875- disjoint if and only if their intersection is the empty set.
4875+ Return ``True `` if the set has no elements in common with *other *. Sets are
4876+ disjoint if and only if their intersection is the empty set.
48764877
4877- .. method :: issubset(other, /)
4878- set <= other
4878+ .. method :: frozenset.issubset(other, /)
4879+ set.issubset(other, /)
4880+ .. describe :: set <= other
48794881
4880- Test whether every element in the set is in *other *.
4882+ Test whether every element in the set is in *other *.
48814883
4882- .. method :: set < other
4884+ .. describe :: set < other
48834885
4884- Test whether the set is a proper subset of *other *, that is,
4885- ``set <= other and set != other ``.
4886+ Test whether the set is a proper subset of *other *, that is,
4887+ ``set <= other and set != other ``.
48864888
4887- .. method :: issuperset(other, /)
4888- set >= other
4889+ .. method :: frozenset.issuperset(other, /)
4890+ set.issuperset(other, /)
4891+ .. describe :: set >= other
48894892
4890- Test whether every element in *other * is in the set.
4893+ Test whether every element in *other * is in the set.
48914894
4892- .. method :: set > other
4895+ .. describe :: set > other
48934896
4894- Test whether the set is a proper superset of *other *, that is, ``set >=
4895- other and set != other ``.
4897+ Test whether the set is a proper superset of *other *, that is, ``set >=
4898+ other and set != other ``.
48964899
4897- .. method :: union(*others)
4898- set | other | ...
4900+ .. method :: frozenset.union(*others)
4901+ set.union(*others)
4902+ .. describe:: set | other | ...
48994903
4900- Return a new set with elements from the set and all others.
4904+ Return a new set with elements from the set and all others.
49014905
4902- .. method :: intersection(*others)
4903- set & other & ...
4906+ .. method :: frozenset.intersection(*others)
4907+ set.intersection(*others)
4908+ .. describe:: set & other & ...
49044909
4905- Return a new set with elements common to the set and all others.
4910+ Return a new set with elements common to the set and all others.
49064911
4907- .. method :: difference(*others)
4908- set - other - ...
4912+ .. method :: frozenset.difference(*others)
4913+ set.difference(*others)
4914+ .. describe:: set - other - ...
49094915
4910- Return a new set with elements in the set that are not in the others.
4916+ Return a new set with elements in the set that are not in the others.
49114917
4912- .. method :: symmetric_difference(other, /)
4913- set ^ other
4918+ .. method :: frozenset.symmetric_difference(other, /)
4919+ set.symmetric_difference(other, /)
4920+ .. describe :: set ^ other
49144921
4915- Return a new set with elements in either the set or *other * but not both.
4922+ Return a new set with elements in either the set or *other * but not both.
49164923
4917- .. method :: copy()
4924+ .. method :: frozenset.copy()
4925+ set.copy()
49184926
4919- Return a shallow copy of the set.
4927+ Return a shallow copy of the set.
49204928
49214929
4922- Note, the non-operator versions of :meth: `union `, :meth: ` intersection `,
4923- :meth: `difference `, :meth: `symmetric_difference `, :meth: `issubset `, and
4924- :meth: `issuperset ` methods will accept any iterable as an argument. In
4925- contrast, their operator based counterparts require their arguments to be
4926- sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4927- in favor of the more readable ``set('abc').intersection('cbs') ``.
4930+ Note, the non-operator versions of :meth: `~frozenset. union `,
4931+ :meth: ` ~frozenset.intersection `, :meth: `~frozenset. difference `, :meth: `~frozenset. symmetric_difference `, :meth: `~frozenset. issubset `, and
4932+ :meth: `~frozenset. issuperset ` methods will accept any iterable as an argument. In
4933+ contrast, their operator based counterparts require their arguments to be
4934+ sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4935+ in favor of the more readable ``set('abc').intersection('cbs') ``.
49284936
4929- Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4930- sets are equal if and only if every element of each set is contained in the
4931- other (each is a subset of the other). A set is less than another set if and
4932- only if the first set is a proper subset of the second set (is a subset, but
4933- is not equal). A set is greater than another set if and only if the first set
4934- is a proper superset of the second set (is a superset, but is not equal).
4937+ Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4938+ sets are equal if and only if every element of each set is contained in the
4939+ other (each is a subset of the other). A set is less than another set if and
4940+ only if the first set is a proper subset of the second set (is a subset, but
4941+ is not equal). A set is greater than another set if and only if the first set
4942+ is a proper superset of the second set (is a superset, but is not equal).
49354943
4936- Instances of :class: `set ` are compared to instances of :class: `frozenset `
4937- based on their members. For example, ``set('abc') == frozenset('abc') ``
4938- returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
4944+ Instances of :class: `set ` are compared to instances of :class: `frozenset `
4945+ based on their members. For example, ``set('abc') == frozenset('abc') ``
4946+ returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
49394947
4940- The subset and equality comparisons do not generalize to a total ordering
4941- function. For example, any two nonempty disjoint sets are not equal and are not
4942- subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4943- ``a==b ``, or ``a>b ``.
4948+ The subset and equality comparisons do not generalize to a total ordering
4949+ function. For example, any two nonempty disjoint sets are not equal and are not
4950+ subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4951+ ``a==b ``, or ``a>b ``.
49444952
4945- Since sets only define partial ordering (subset relationships), the output of
4946- the :meth: `list.sort ` method is undefined for lists of sets.
4953+ Since sets only define partial ordering (subset relationships), the output of
4954+ the :meth: `list.sort ` method is undefined for lists of sets.
49474955
4948- Set elements, like dictionary keys, must be :term: `hashable `.
4956+ Set elements, like dictionary keys, must be :term: `hashable `.
49494957
4950- Binary operations that mix :class: `set ` instances with :class: `frozenset `
4951- return the type of the first operand. For example: ``frozenset('ab') |
4952- set('bc') `` returns an instance of :class: `frozenset `.
4958+ Binary operations that mix :class: `set ` instances with :class: `frozenset `
4959+ return the type of the first operand. For example: ``frozenset('ab') |
4960+ set('bc') `` returns an instance of :class: `frozenset `.
49534961
4954- The following table lists operations available for :class: `set ` that do not
4955- apply to immutable instances of :class: `frozenset `:
4962+ The following table lists operations available for :class: `set ` that do not
4963+ apply to immutable instances of :class: `frozenset `:
49564964
4957- .. method :: update(*others)
4958- set |= other | ...
4965+ .. method :: set. update(*others)
4966+ .. describe :: set |= other | ...
49594967
4960- Update the set, adding elements from all others.
4968+ Update the set, adding elements from all others.
49614969
4962- .. method :: intersection_update(*others)
4963- set &= other & ...
4970+ .. method :: set. intersection_update(*others)
4971+ .. describe :: set &= other & ...
49644972
4965- Update the set, keeping only elements found in it and all others.
4973+ Update the set, keeping only elements found in it and all others.
49664974
4967- .. method :: difference_update(*others)
4968- set -= other | ...
4975+ .. method :: set. difference_update(*others)
4976+ .. describe :: set -= other | ...
49694977
4970- Update the set, removing elements found in others.
4978+ Update the set, removing elements found in others.
49714979
4972- .. method :: symmetric_difference_update(other, /)
4973- set ^= other
4980+ .. method :: set. symmetric_difference_update(other, /)
4981+ .. describe :: set ^= other
49744982
4975- Update the set, keeping only elements found in either set, but not in both.
4983+ Update the set, keeping only elements found in either set, but not in both.
49764984
4977- .. method :: add(elem, /)
4985+ .. method :: set. add(elem, /)
49784986
4979- Add element *elem * to the set.
4987+ Add element *elem * to the set.
49804988
4981- .. method :: remove(elem, /)
4989+ .. method :: set. remove(elem, /)
49824990
4983- Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4984- not contained in the set.
4991+ Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4992+ not contained in the set.
49854993
4986- .. method :: discard(elem, /)
4994+ .. method :: set. discard(elem, /)
49874995
4988- Remove element *elem * from the set if it is present.
4996+ Remove element *elem * from the set if it is present.
49894997
4990- .. method :: pop()
4998+ .. method :: set. pop()
49914999
4992- Remove and return an arbitrary element from the set. Raises
4993- :exc: `KeyError ` if the set is empty.
5000+ Remove and return an arbitrary element from the set. Raises
5001+ :exc: `KeyError ` if the set is empty.
49945002
4995- .. method :: clear()
5003+ .. method :: set. clear()
49965004
4997- Remove all elements from the set.
5005+ Remove all elements from the set.
49985006
49995007
5000- Note, the non-operator versions of the :meth: `update `,
5001- :meth: `intersection_update `, :meth: `difference_update `, and
5002- :meth: `symmetric_difference_update ` methods will accept any iterable as an
5003- argument.
5008+ Note, the non-operator versions of the :meth: `~set. update `,
5009+ :meth: `~set. intersection_update `, :meth: `~set. difference_update `, and
5010+ :meth: `~set. symmetric_difference_update ` methods will accept any iterable as an
5011+ argument.
50045012
5005- Note, the *elem * argument to the :meth: `~object.__contains__ `,
5006- :meth: `remove `, and
5007- :meth: `discard ` methods may be a set. To support searching for an equivalent
5008- frozenset, a temporary one is created from *elem *.
5013+ Note, the *elem * argument to the :meth: `~object.__contains__ `,
5014+ :meth: `~set. remove `, and
5015+ :meth: `~set. discard ` methods may be a set. To support searching for an equivalent
5016+ frozenset, a temporary one is created from *elem *.
50095017
50105018
50115019.. _typesmapping :
0 commit comments