@@ -4802,7 +4802,7 @@ other sequence-like behavior.
48024802
48034803There are currently two built-in set types, :class: `set ` and :class: `frozenset `.
48044804The :class: `set ` type is mutable --- the contents can be changed using methods
4805- like :meth: `add <frozenset .add> ` and :meth: `remove <frozenset.add> `.
4805+ like :meth: `~set .add ` and :meth: `~set.remove `.
48064806Since it is mutable, it has no hash value and cannot be used as
48074807either a dictionary key or as an element of another set.
48084808The :class: `frozenset ` type is immutable and :term: `hashable ` ---
@@ -4824,164 +4824,172 @@ The constructors for both classes work the same:
48244824 objects. If *iterable * is not specified, a new empty set is
48254825 returned.
48264826
4827- Sets can be created by several means:
4827+ Sets can be created by several means:
48284828
4829- * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4830- * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4831- * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
4829+ * Use a comma-separated list of elements within braces: ``{'jack', 'sjoerd'} ``
4830+ * Use a set comprehension: ``{c for c in 'abracadabra' if c not in 'abc'} ``
4831+ * Use the type constructor: ``set() ``, ``set('foobar') ``, ``set(['a', 'b', 'foo']) ``
48324832
4833- Instances of :class: `set ` and :class: `frozenset ` provide the following
4834- operations:
4833+ Instances of :class: `set ` and :class: `frozenset ` provide the following
4834+ operations:
48354835
4836- .. describe :: len(s)
4836+ .. describe :: len(s)
48374837
4838- Return the number of elements in set *s * (cardinality of *s *).
4838+ Return the number of elements in set *s * (cardinality of *s *).
48394839
4840- .. describe :: x in s
4840+ .. describe :: x in s
48414841
4842- Test *x * for membership in *s *.
4842+ Test *x * for membership in *s *.
48434843
4844- .. describe :: x not in s
4844+ .. describe :: x not in s
48454845
4846- Test *x * for non-membership in *s *.
4846+ Test *x * for non-membership in *s *.
48474847
4848- .. method :: isdisjoint(other, /)
4848+ .. method :: frozenset.isdisjoint(other, /)
4849+ set.isdisjoint(other, /)
48494850
4850- Return ``True `` if the set has no elements in common with *other *. Sets are
4851- disjoint if and only if their intersection is the empty set.
4851+ Return ``True `` if the set has no elements in common with *other *. Sets are
4852+ disjoint if and only if their intersection is the empty set.
48524853
4853- .. method :: issubset(other, /)
4854- set <= other
4854+ .. method :: frozenset.issubset(other, /)
4855+ set.issubset(other, /)
4856+ .. describe :: set <= other
48554857
4856- Test whether every element in the set is in *other *.
4858+ Test whether every element in the set is in *other *.
48574859
4858- .. method :: set < other
4860+ .. describe :: set < other
48594861
4860- Test whether the set is a proper subset of *other *, that is,
4861- ``set <= other and set != other ``.
4862+ Test whether the set is a proper subset of *other *, that is,
4863+ ``set <= other and set != other ``.
48624864
4863- .. method :: issuperset(other, /)
4864- set >= other
4865+ .. method :: frozenset.issuperset(other, /)
4866+ set.issuperset(other, /)
4867+ .. describe :: set >= other
48654868
4866- Test whether every element in *other * is in the set.
4869+ Test whether every element in *other * is in the set.
48674870
4868- .. method :: set > other
4871+ .. describe :: set > other
48694872
4870- Test whether the set is a proper superset of *other *, that is, ``set >=
4871- other and set != other ``.
4873+ Test whether the set is a proper superset of *other *, that is, ``set >=
4874+ other and set != other ``.
48724875
4873- .. method :: union(*others)
4874- set | other | ...
4876+ .. method :: frozenset.union(*others)
4877+ set.union(*others)
4878+ .. describe:: set | other | ...
48754879
4876- Return a new set with elements from the set and all others.
4880+ Return a new set with elements from the set and all others.
48774881
4878- .. method :: intersection(*others)
4879- set & other & ...
4882+ .. method :: frozenset.intersection(*others)
4883+ set.intersection(*others)
4884+ .. describe:: set & other & ...
48804885
4881- Return a new set with elements common to the set and all others.
4886+ Return a new set with elements common to the set and all others.
48824887
4883- .. method :: difference(*others)
4884- set - other - ...
4888+ .. method :: frozenset.difference(*others)
4889+ set.difference(*others)
4890+ .. describe:: set - other - ...
48854891
4886- Return a new set with elements in the set that are not in the others.
4892+ Return a new set with elements in the set that are not in the others.
48874893
4888- .. method :: symmetric_difference(other, /)
4889- set ^ other
4894+ .. method :: frozenset.symmetric_difference(other, /)
4895+ set.symmetric_difference(other, /)
4896+ .. describe :: set ^ other
48904897
4891- Return a new set with elements in either the set or *other * but not both.
4898+ Return a new set with elements in either the set or *other * but not both.
48924899
4893- .. method :: copy()
4900+ .. method :: frozenset.copy()
4901+ set.copy()
48944902
4895- Return a shallow copy of the set.
4903+ Return a shallow copy of the set.
48964904
48974905
4898- Note, the non-operator versions of :meth: `union `, :meth: ` intersection `,
4899- :meth: `difference `, :meth: `symmetric_difference `, :meth: `issubset `, and
4900- :meth: `issuperset ` methods will accept any iterable as an argument. In
4901- contrast, their operator based counterparts require their arguments to be
4902- sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4903- in favor of the more readable ``set('abc').intersection('cbs') ``.
4906+ Note, the non-operator versions of :meth: `~frozenset. union `,
4907+ :meth: ` ~frozenset.intersection `, :meth: `~frozenset. difference `, :meth: `~frozenset. symmetric_difference `, :meth: `~frozenset. issubset `, and
4908+ :meth: `~frozenset. issuperset ` methods will accept any iterable as an argument. In
4909+ contrast, their operator based counterparts require their arguments to be
4910+ sets. This precludes error-prone constructions like ``set('abc') & 'cbs' ``
4911+ in favor of the more readable ``set('abc').intersection('cbs') ``.
49044912
4905- Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4906- sets are equal if and only if every element of each set is contained in the
4907- other (each is a subset of the other). A set is less than another set if and
4908- only if the first set is a proper subset of the second set (is a subset, but
4909- is not equal). A set is greater than another set if and only if the first set
4910- is a proper superset of the second set (is a superset, but is not equal).
4913+ Both :class: `set ` and :class: `frozenset ` support set to set comparisons. Two
4914+ sets are equal if and only if every element of each set is contained in the
4915+ other (each is a subset of the other). A set is less than another set if and
4916+ only if the first set is a proper subset of the second set (is a subset, but
4917+ is not equal). A set is greater than another set if and only if the first set
4918+ is a proper superset of the second set (is a superset, but is not equal).
49114919
4912- Instances of :class: `set ` are compared to instances of :class: `frozenset `
4913- based on their members. For example, ``set('abc') == frozenset('abc') ``
4914- returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
4920+ Instances of :class: `set ` are compared to instances of :class: `frozenset `
4921+ based on their members. For example, ``set('abc') == frozenset('abc') ``
4922+ returns ``True `` and so does ``set('abc') in set([frozenset('abc')]) ``.
49154923
4916- The subset and equality comparisons do not generalize to a total ordering
4917- function. For example, any two nonempty disjoint sets are not equal and are not
4918- subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4919- ``a==b ``, or ``a>b ``.
4924+ The subset and equality comparisons do not generalize to a total ordering
4925+ function. For example, any two nonempty disjoint sets are not equal and are not
4926+ subsets of each other, so *all * of the following return ``False ``: ``a<b ``,
4927+ ``a==b ``, or ``a>b ``.
49204928
4921- Since sets only define partial ordering (subset relationships), the output of
4922- the :meth: `list.sort ` method is undefined for lists of sets.
4929+ Since sets only define partial ordering (subset relationships), the output of
4930+ the :meth: `list.sort ` method is undefined for lists of sets.
49234931
4924- Set elements, like dictionary keys, must be :term: `hashable `.
4932+ Set elements, like dictionary keys, must be :term: `hashable `.
49254933
4926- Binary operations that mix :class: `set ` instances with :class: `frozenset `
4927- return the type of the first operand. For example: ``frozenset('ab') |
4928- set('bc') `` returns an instance of :class: `frozenset `.
4934+ Binary operations that mix :class: `set ` instances with :class: `frozenset `
4935+ return the type of the first operand. For example: ``frozenset('ab') |
4936+ set('bc') `` returns an instance of :class: `frozenset `.
49294937
4930- The following table lists operations available for :class: `set ` that do not
4931- apply to immutable instances of :class: `frozenset `:
4938+ The following table lists operations available for :class: `set ` that do not
4939+ apply to immutable instances of :class: `frozenset `:
49324940
4933- .. method :: update(*others)
4934- set |= other | ...
4941+ .. method :: set. update(*others)
4942+ .. describe :: set |= other | ...
49354943
4936- Update the set, adding elements from all others.
4944+ Update the set, adding elements from all others.
49374945
4938- .. method :: intersection_update(*others)
4939- set &= other & ...
4946+ .. method :: set. intersection_update(*others)
4947+ .. describe :: set &= other & ...
49404948
4941- Update the set, keeping only elements found in it and all others.
4949+ Update the set, keeping only elements found in it and all others.
49424950
4943- .. method :: difference_update(*others)
4944- set -= other | ...
4951+ .. method :: set. difference_update(*others)
4952+ .. describe :: set -= other | ...
49454953
4946- Update the set, removing elements found in others.
4954+ Update the set, removing elements found in others.
49474955
4948- .. method :: symmetric_difference_update(other, /)
4949- set ^= other
4956+ .. method :: set. symmetric_difference_update(other, /)
4957+ .. describe :: set ^= other
49504958
4951- Update the set, keeping only elements found in either set, but not in both.
4959+ Update the set, keeping only elements found in either set, but not in both.
49524960
4953- .. method :: add(elem, /)
4961+ .. method :: set. add(elem, /)
49544962
4955- Add element *elem * to the set.
4963+ Add element *elem * to the set.
49564964
4957- .. method :: remove(elem, /)
4965+ .. method :: set. remove(elem, /)
49584966
4959- Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4960- not contained in the set.
4967+ Remove element *elem * from the set. Raises :exc: `KeyError ` if *elem * is
4968+ not contained in the set.
49614969
4962- .. method :: discard(elem, /)
4970+ .. method :: set. discard(elem, /)
49634971
4964- Remove element *elem * from the set if it is present.
4972+ Remove element *elem * from the set if it is present.
49654973
4966- .. method :: pop()
4974+ .. method :: set. pop()
49674975
4968- Remove and return an arbitrary element from the set. Raises
4969- :exc: `KeyError ` if the set is empty.
4976+ Remove and return an arbitrary element from the set. Raises
4977+ :exc: `KeyError ` if the set is empty.
49704978
4971- .. method :: clear()
4979+ .. method :: set. clear()
49724980
4973- Remove all elements from the set.
4981+ Remove all elements from the set.
49744982
49754983
4976- Note, the non-operator versions of the :meth: `update `,
4977- :meth: `intersection_update `, :meth: `difference_update `, and
4978- :meth: `symmetric_difference_update ` methods will accept any iterable as an
4979- argument.
4984+ Note, the non-operator versions of the :meth: `~set. update `,
4985+ :meth: `~set. intersection_update `, :meth: `~set. difference_update `, and
4986+ :meth: `~set. symmetric_difference_update ` methods will accept any iterable as an
4987+ argument.
49804988
4981- Note, the *elem * argument to the :meth: `~object.__contains__ `,
4982- :meth: `remove `, and
4983- :meth: `discard ` methods may be a set. To support searching for an equivalent
4984- frozenset, a temporary one is created from *elem *.
4989+ Note, the *elem * argument to the :meth: `~object.__contains__ `,
4990+ :meth: `~set. remove `, and
4991+ :meth: `~set. discard ` methods may be a set. To support searching for an equivalent
4992+ frozenset, a temporary one is created from *elem *.
49854993
49864994
49874995.. _typesmapping :
0 commit comments