@@ -4755,7 +4755,7 @@ other sequence-like behavior.
47554755
47564756There are currently two built-in set types, :class: `set ` and :class: `frozenset `.
47574757The :class: `set ` type is mutable --- the contents can be changed using methods
4758- like :meth: `add <frozenset .add> ` and :meth: `remove <frozenset.add> `.
4758+ like :meth: `~set .add ` and :meth: `~set.remove `.
47594759Since it is mutable, it has no hash value and cannot be used as
47604760either a dictionary key or as an element of another set.
47614761The :class: `frozenset ` type is immutable and :term: `hashable ` ---
@@ -4777,164 +4777,172 @@ The constructors for both classes work the same:
47774777 objects. If *iterable * is not specified, a new empty set is
47784778 returned.
47794779
4780- Sets can be created by several means:
4780+ Sets can be created by several means:
47814781
4782- * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4783- * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4784- * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
4782+ * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4783+ * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4784+ * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
47854785
4786- Instances of :class: `set ` and :class: `frozenset ` provide the following
4787- operations:
4786+ Instances of :class: `set ` and :class: `frozenset ` provide the following
4787+ operations:
47884788
4789- .. describe :: len(s)
4789+ .. describe :: len(s)
47904790
4791- Return the number of elements in set *s * (cardinality of *s *).
4791+ Return the number of elements in set *s * (cardinality of *s *).
47924792
4793- .. describe :: x in s
4793+ .. describe :: x in s
47944794
4795- Test *x * for membership in *s *.
4795+ Test *x * for membership in *s *.
47964796
4797- .. describe :: x not in s
4797+ .. describe :: x not in s
47984798
4799- Test *x * for non-membership in *s *.
4799+ Test *x * for non-membership in *s *.
48004800
4801- .. method :: isdisjoint(other, /)
4801+ .. method :: frozenset.isdisjoint(other, /)
4802+ set.isdisjoint(other, /)
48024803
4803- Return ``True `` if the set has no elements in common with *other *. Sets are
4804- disjoint if and only if their intersection is the empty set.
4804+ Return ``True `` if the set has no elements in common with *other *. Sets are
4805+ disjoint if and only if their intersection is the empty set.
48054806
4806- .. method :: issubset(other, /)
4807- set <= other
4807+ .. method :: frozenset.issubset(other, /)
4808+ set.issubset(other, /)
4809+ .. describe :: set <= other
48084810
4809- Test whether every element in the set is in *other *.
4811+ Test whether every element in the set is in *other *.
48104812
4811- .. method :: set < other
4813+ .. describe :: set < other
48124814
4813- Test whether the set is a proper subset of *other *, that is,
4814- ``set <= other and set != other ``.
4815+ Test whether the set is a proper subset of *other *, that is,
4816+ ``set <= other and set != other ``.
48154817
4816- .. method :: issuperset(other, /)
4817- set >= other
4818+ .. method :: frozenset.issuperset(other, /)
4819+ set.issuperset(other, /)
4820+ .. describe :: set >= other
48184821
4819- Test whether every element in *other * is in the set.
4822+ Test whether every element in *other * is in the set.
48204823
4821- .. method :: set > other
4824+ .. describe :: set > other
48224825
4823- Test whether the set is a proper superset of *other *, that is, ``set >=
4824- other and set != other ``.
4826+ Test whether the set is a proper superset of *other *, that is, ``set >=
4827+ other and set != other ``.
48254828
4826- .. method :: union(*others)
4827- set | other | ...
4829+ .. method :: frozenset.union(*others)
4830+ set.union(*others)
4831+ .. describe:: set | other | ...
48284832
4829- Return a new set with elements from the set and all others.
4833+ Return a new set with elements from the set and all others.
48304834
4831- .. method :: intersection(*others)
4832- set & other & ...
4835+ .. method :: frozenset.intersection(*others)
4836+ set.intersection(*others)
4837+ .. describe:: set & other & ...
48334838
4834- Return a new set with elements common to the set and all others.
4839+ Return a new set with elements common to the set and all others.
48354840
4836- .. method :: difference(*others)
4837- set - other - ...
4841+ .. method :: frozenset.difference(*others)
4842+ set.difference(*others)
4843+ .. describe:: set - other - ...
48384844
4839- Return a new set with elements in the set that are not in the others.
4845+ Return a new set with elements in the set that are not in the others.
48404846
4841- .. method :: symmetric_difference(other, /)
4842- set ^ other
4847+ .. method :: frozenset.symmetric_difference(other, /)
4848+ set.symmetric_difference(other, /)
4849+ .. describe :: set ^ other
48434850
4844- Return a new set with elements in either the set or *other * but not both.
4851+ Return a new set with elements in either the set or *other * but not both.
48454852
4846- .. method :: copy()
4853+ .. method :: frozenset.copy()
4854+ set.copy()
48474855
4848- Return a shallow copy of the set.
4856+ Return a shallow copy of the set.
48494857
48504858
4851- Note, the non-operator versions of :meth: `union `, :meth: `intersection `,
4852- :meth: `difference `, :meth: `symmetric_difference `, :meth: `issubset `, and
4853- :meth: `issuperset ` methods will accept any iterable as an argument. In
4854- contrast, their operator based counterparts require their arguments to be
4855- sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4856- in favor of the more readable ``set('abc').intersection('cbs') ``.
4859+ Note, the non-operator versions of :meth: `union `, :meth: `intersection `,
4860+ :meth: `difference `, :meth: `symmetric_difference `, :meth: `issubset `, and
4861+ :meth: `issuperset ` methods will accept any iterable as an argument. In
4862+ contrast, their operator based counterparts require their arguments to be
4863+ sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4864+ in favor of the more readable ``set('abc').intersection('cbs') ``.
48574865
4858- Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4859- sets are equal if and only if every element of each set is contained in the
4860- other (each is a subset of the other). A set is less than another set if and
4861- only if the first set is a proper subset of the second set (is a subset, but
4862- is not equal). A set is greater than another set if and only if the first set
4863- is a proper superset of the second set (is a superset, but is not equal).
4866+ Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4867+ sets are equal if and only if every element of each set is contained in the
4868+ other (each is a subset of the other). A set is less than another set if and
4869+ only if the first set is a proper subset of the second set (is a subset, but
4870+ is not equal). A set is greater than another set if and only if the first set
4871+ is a proper superset of the second set (is a superset, but is not equal).
48644872
4865- Instances of :class: `set ` are compared to instances of :class: `frozenset `
4866- based on their members. For example, ``set('abc') == frozenset('abc') ``
4867- returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
4873+ Instances of :class: `set ` are compared to instances of :class: `frozenset `
4874+ based on their members. For example, ``set('abc') == frozenset('abc') ``
4875+ returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
48684876
4869- The subset and equality comparisons do not generalize to a total ordering
4870- function. For example, any two nonempty disjoint sets are not equal and are not
4871- subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4872- ``a==b ``, or ``a>b ``.
4877+ The subset and equality comparisons do not generalize to a total ordering
4878+ function. For example, any two nonempty disjoint sets are not equal and are not
4879+ subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4880+ ``a==b ``, or ``a>b ``.
48734881
4874- Since sets only define partial ordering (subset relationships), the output of
4875- the :meth: `list.sort ` method is undefined for lists of sets.
4882+ Since sets only define partial ordering (subset relationships), the output of
4883+ the :meth: `list.sort ` method is undefined for lists of sets.
48764884
4877- Set elements, like dictionary keys, must be :term: `hashable `.
4885+ Set elements, like dictionary keys, must be :term: `hashable `.
48784886
4879- Binary operations that mix :class: `set ` instances with :class: `frozenset `
4880- return the type of the first operand. For example: ``frozenset('ab') |
4881- set('bc') `` returns an instance of :class: `frozenset `.
4887+ Binary operations that mix :class: `set ` instances with :class: `frozenset `
4888+ return the type of the first operand. For example: ``frozenset('ab') |
4889+ set('bc') `` returns an instance of :class: `frozenset `.
48824890
4883- The following table lists operations available for :class: `set ` that do not
4884- apply to immutable instances of :class: `frozenset `:
4891+ The following table lists operations available for :class: `set ` that do not
4892+ apply to immutable instances of :class: `frozenset `:
48854893
4886- .. method :: update(*others)
4887- set |= other | ...
4894+ .. method :: set. update(*others)
4895+ .. describe :: set |= other | ...
48884896
4889- Update the set, adding elements from all others.
4897+ Update the set, adding elements from all others.
48904898
4891- .. method :: intersection_update(*others)
4892- set &= other & ...
4899+ .. method :: set. intersection_update(*others)
4900+ .. describe :: set &= other & ...
48934901
4894- Update the set, keeping only elements found in it and all others.
4902+ Update the set, keeping only elements found in it and all others.
48954903
4896- .. method :: difference_update(*others)
4897- set -= other | ...
4904+ .. method :: set. difference_update(*others)
4905+ .. describe :: set -= other | ...
48984906
4899- Update the set, removing elements found in others.
4907+ Update the set, removing elements found in others.
49004908
4901- .. method :: symmetric_difference_update(other, /)
4902- set ^= other
4909+ .. method :: set. symmetric_difference_update(other, /)
4910+ .. describe :: set ^= other
49034911
4904- Update the set, keeping only elements found in either set, but not in both.
4912+ Update the set, keeping only elements found in either set, but not in both.
49054913
4906- .. method :: add(elem, /)
4914+ .. method :: set. add(elem, /)
49074915
4908- Add element *elem * to the set.
4916+ Add element *elem * to the set.
49094917
4910- .. method :: remove(elem, /)
4918+ .. method :: set. remove(elem, /)
49114919
4912- Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4913- not contained in the set.
4920+ Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4921+ not contained in the set.
49144922
4915- .. method :: discard(elem, /)
4923+ .. method :: set. discard(elem, /)
49164924
4917- Remove element *elem * from the set if it is present.
4925+ Remove element *elem * from the set if it is present.
49184926
4919- .. method :: pop()
4927+ .. method :: set. pop()
49204928
4921- Remove and return an arbitrary element from the set. Raises
4922- :exc: `KeyError ` if the set is empty.
4929+ Remove and return an arbitrary element from the set. Raises
4930+ :exc: `KeyError ` if the set is empty.
49234931
4924- .. method :: clear()
4932+ .. method :: set. clear()
49254933
4926- Remove all elements from the set.
4934+ Remove all elements from the set.
49274935
49284936
4929- Note, the non-operator versions of the :meth: `update `,
4930- :meth: `intersection_update `, :meth: `difference_update `, and
4931- :meth: `symmetric_difference_update ` methods will accept any iterable as an
4932- argument.
4937+ Note, the non-operator versions of the :meth: `update `,
4938+ :meth: `intersection_update `, :meth: `difference_update `, and
4939+ :meth: `symmetric_difference_update ` methods will accept any iterable as an
4940+ argument.
49334941
4934- Note, the *elem * argument to the :meth: `~object.__contains__ `,
4935- :meth: `remove `, and
4936- :meth: `discard ` methods may be a set. To support searching for an equivalent
4937- frozenset, a temporary one is created from *elem *.
4942+ Note, the *elem * argument to the :meth: `~object.__contains__ `,
4943+ :meth: `remove `, and
4944+ :meth: `discard ` methods may be a set. To support searching for an equivalent
4945+ frozenset, a temporary one is created from *elem *.
49384946
49394947
49404948.. _typesmapping :
0 commit comments