| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes. | |||
| 147 | 147 | ||
| 148 | 148 | Return ``1`` if found and removed, ``0`` if not found (no action taken), and ``-1`` if an | |
| 149 | 149 | error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a | |
| 150 | - :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~frozenset.discard` | ||
| 150 | + :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` | ||
| 151 | 151 | method, this function does not automatically convert unhashable sets into | |
| 152 | 152 | temporary frozensets. Raise :exc:`SystemError` if *set* is not an | |
| 153 | 153 | instance of :class:`set` or its subtype. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4802,7 +4802,7 @@ other sequence-like behavior. | |||
| 4802 | 4802 | ||
| 4803 | 4803 | There are currently two built-in set types, :class:`set` and :class:`frozenset`. | |
| 4804 | 4804 | The :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`. | ||
| 4806 | 4806 | Since it is mutable, it has no hash value and cannot be used as | |
| 4807 | 4807 | either a dictionary key or as an element of another set. | |
| 4808 | 4808 | The :class:`frozenset` type is immutable and :term:`hashable` --- | |
@@ -4824,164 +4824,172 @@ The constructors for both classes work the same: | |||
| 4824 | 4824 | objects. If *iterable* is not specified, a new empty set is | |
| 4825 | 4825 | returned. | |
| 4826 | 4826 | ||
| 4827 | - Sets can be created by several means: | ||
| 4827 | + Sets can be created by several means: | ||
| 4828 | 4828 | ||
| 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'])`` | ||
| 4832 | 4832 | ||
| 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: | ||
| 4835 | 4835 | ||
| 4836 | - .. describe:: len(s) | ||
| 4836 | + .. describe:: len(s) | ||
| 4837 | 4837 | ||
| 4838 | - Return the number of elements in set *s* (cardinality of *s*). | ||
| 4838 | + Return the number of elements in set *s* (cardinality of *s*). | ||
| 4839 | 4839 | ||
| 4840 | - .. describe:: x in s | ||
| 4840 | + .. describe:: x in s | ||
| 4841 | 4841 | ||
| 4842 | - Test *x* for membership in *s*. | ||
| 4842 | + Test *x* for membership in *s*. | ||
| 4843 | 4843 | ||
| 4844 | - .. describe:: x not in s | ||
| 4844 | + .. describe:: x not in s | ||
| 4845 | 4845 | ||
| 4846 | - Test *x* for non-membership in *s*. | ||
| 4846 | + Test *x* for non-membership in *s*. | ||
| 4847 | 4847 | ||
| 4848 | - .. method:: isdisjoint(other, /) | ||
| 4848 | + .. method:: frozenset.isdisjoint(other, /) | ||
| 4849 | + set.isdisjoint(other, /) | ||
| 4849 | 4850 | ||
| 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. | ||
| 4852 | 4853 | ||
| 4853 | - .. method:: issubset(other, /) | ||
| 4854 | - set <= other | ||
| 4854 | + .. method:: frozenset.issubset(other, /) | ||
| 4855 | + set.issubset(other, /) | ||
| 4856 | + .. describe:: set <= other | ||
| 4855 | 4857 | ||
| 4856 | - Test whether every element in the set is in *other*. | ||
| 4858 | + Test whether every element in the set is in *other*. | ||
| 4857 | 4859 | ||
| 4858 | - .. method:: set < other | ||
| 4860 | + .. describe:: set < other | ||
| 4859 | 4861 | ||
| 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``. | ||
| 4862 | 4864 | ||
| 4863 | - .. method:: issuperset(other, /) | ||
| 4864 | - set >= other | ||
| 4865 | + .. method:: frozenset.issuperset(other, /) | ||
| 4866 | + set.issuperset(other, /) | ||
| 4867 | + .. describe:: set >= other | ||
| 4865 | 4868 | ||
| 4866 | - Test whether every element in *other* is in the set. | ||
| 4869 | + Test whether every element in *other* is in the set. | ||
| 4867 | 4870 | ||
| 4868 | - .. method:: set > other | ||
| 4871 | + .. describe:: set > other | ||
| 4869 | 4872 | ||
| 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``. | ||
| 4872 | 4875 | ||
| 4873 | - .. method:: union(*others) | ||
| 4874 | - set | other | ... | ||
| 4876 | + .. method:: frozenset.union(*others) | ||
| 4877 | + set.union(*others) | ||
| 4878 | + .. describe:: set | other | ... | ||
| 4875 | 4879 | ||
| 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. | ||
| 4877 | 4881 | ||
| 4878 | - .. method:: intersection(*others) | ||
| 4879 | - set & other & ... | ||
| 4882 | + .. method:: frozenset.intersection(*others) | ||
| 4883 | + set.intersection(*others) | ||
| 4884 | + .. describe:: set & other & ... | ||
| 4880 | 4885 | ||
| 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. | ||
| 4882 | 4887 | ||
| 4883 | - .. method:: difference(*others) | ||
| 4884 | - set - other - ... | ||
| 4888 | + .. method:: frozenset.difference(*others) | ||
| 4889 | + set.difference(*others) | ||
| 4890 | + .. describe:: set - other - ... | ||
| 4885 | 4891 | ||
| 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. | ||
| 4887 | 4893 | ||
| 4888 | - .. method:: symmetric_difference(other, /) | ||
| 4889 | - set ^ other | ||
| 4894 | + .. method:: frozenset.symmetric_difference(other, /) | ||
| 4895 | + set.symmetric_difference(other, /) | ||
| 4896 | + .. describe:: set ^ other | ||
| 4890 | 4897 | ||
| 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. | ||
| 4892 | 4899 | ||
| 4893 | - .. method:: copy() | ||
| 4900 | + .. method:: frozenset.copy() | ||
| 4901 | + set.copy() | ||
| 4894 | 4902 | ||
| 4895 | - Return a shallow copy of the set. | ||
| 4903 | + Return a shallow copy of the set. | ||
| 4896 | 4904 | ||
| 4897 | 4905 | ||
| 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')``. | ||
| 4904 | 4912 | ||
| 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). | ||
| 4911 | 4919 | ||
| 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')])``. | ||
| 4915 | 4923 | ||
| 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``. | ||
| 4920 | 4928 | ||
| 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. | ||
| 4923 | 4931 | ||
| 4924 | - Set elements, like dictionary keys, must be :term:`hashable`. | ||
| 4932 | + Set elements, like dictionary keys, must be :term:`hashable`. | ||
| 4925 | 4933 | ||
| 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`. | ||
| 4929 | 4937 | ||
| 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`: | ||
| 4932 | 4940 | ||
| 4933 | - .. method:: update(*others) | ||
| 4934 | - set |= other | ... | ||
| 4941 | + .. method:: set.update(*others) | ||
| 4942 | + .. describe:: set |= other | ... | ||
| 4935 | 4943 | ||
| 4936 | - Update the set, adding elements from all others. | ||
| 4944 | + Update the set, adding elements from all others. | ||
| 4937 | 4945 | ||
| 4938 | - .. method:: intersection_update(*others) | ||
| 4939 | - set &= other & ... | ||
| 4946 | + .. method:: set.intersection_update(*others) | ||
| 4947 | + .. describe:: set &= other & ... | ||
| 4940 | 4948 | ||
| 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. | ||
| 4942 | 4950 | ||
| 4943 | - .. method:: difference_update(*others) | ||
| 4944 | - set -= other | ... | ||
| 4951 | + .. method:: set.difference_update(*others) | ||
| 4952 | + .. describe:: set -= other | ... | ||
| 4945 | 4953 | ||
| 4946 | - Update the set, removing elements found in others. | ||
| 4954 | + Update the set, removing elements found in others. | ||
| 4947 | 4955 | ||
| 4948 | - .. method:: symmetric_difference_update(other, /) | ||
| 4949 | - set ^= other | ||
| 4956 | + .. method:: set.symmetric_difference_update(other, /) | ||
| 4957 | + .. describe:: set ^= other | ||
| 4950 | 4958 | ||
| 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. | ||
| 4952 | 4960 | ||
| 4953 | - .. method:: add(elem, /) | ||
| 4961 | + .. method:: set.add(elem, /) | ||
| 4954 | 4962 | ||
| 4955 | - Add element *elem* to the set. | ||
| 4963 | + Add element *elem* to the set. | ||
| 4956 | 4964 | ||
| 4957 | - .. method:: remove(elem, /) | ||
| 4965 | + .. method:: set.remove(elem, /) | ||
| 4958 | 4966 | ||
| 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. | ||
| 4961 | 4969 | ||
| 4962 | - .. method:: discard(elem, /) | ||
| 4970 | + .. method:: set.discard(elem, /) | ||
| 4963 | 4971 | ||
| 4964 | - Remove element *elem* from the set if it is present. | ||
| 4972 | + Remove element *elem* from the set if it is present. | ||
| 4965 | 4973 | ||
| 4966 | - .. method:: pop() | ||
| 4974 | + .. method:: set.pop() | ||
| 4967 | 4975 | ||
| 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. | ||
| 4970 | 4978 | ||
| 4971 | - .. method:: clear() | ||
| 4979 | + .. method:: set.clear() | ||
| 4972 | 4980 | ||
| 4973 | - Remove all elements from the set. | ||
| 4981 | + Remove all elements from the set. | ||
| 4974 | 4982 | ||
| 4975 | 4983 | ||
| 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. | ||
| 4980 | 4988 | ||
| 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*. | ||
| 4985 | 4993 | ||
| 4986 | 4994 | ||
| 4987 | 4995 | .. _typesmapping: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -449,7 +449,7 @@ Sets | |||
| 449 | 449 | ||
| 450 | 450 | These represent a mutable set. They are created by the built-in :func:`set` | |
| 451 | 451 | constructor and can be modified afterwards by several methods, such as | |
| 452 | - :meth:`add <frozenset.add>`. | ||
| 452 | + :meth:`~set.add`. | ||
| 453 | 453 | ||
| 454 | 454 | ||
| 455 | 455 | Frozen sets | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,7 @@ Here's a simple example:: | |||
| 66 | 66 | The union and intersection of sets can be computed with the :meth:`~frozenset.union` and | |
| 67 | 67 | :meth:`~frozenset.intersection` methods; an alternative notation uses the bitwise operators | |
| 68 | 68 | ``&`` and ``|``. Mutable sets also have in-place versions of these methods, | |
| 69 | - :meth:`!union_update` and :meth:`~frozenset.intersection_update`. :: | ||
| 69 | + :meth:`!union_update` and :meth:`~set.intersection_update`. :: | ||
| 70 | 70 | ||
| 71 | 71 | >>> S1 = sets.Set([1,2,3]) | |
| 72 | 72 | >>> S2 = sets.Set([4,5,6]) | |
@@ -87,7 +87,7 @@ It's also possible to take the symmetric difference of two sets. This is the | |||
| 87 | 87 | set of all elements in the union that aren't in the intersection. Another way | |
| 88 | 88 | of putting it is that the symmetric difference contains all elements that are in | |
| 89 | 89 | exactly one set. Again, there's an alternative notation (``^``), and an | |
| 90 | - in-place version with the ungainly name :meth:`~frozenset.symmetric_difference_update`. :: | ||
| 90 | + in-place version with the ungainly name :meth:`~set.symmetric_difference_update`. :: | ||
| 91 | 91 | ||
| 92 | 92 | >>> S1 = sets.Set([1,2,3,4]) | |
| 93 | 93 | >>> S2 = sets.Set([3,4,5,6]) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments