-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Corrected link targets in collections.rst #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 6 commits into
python:master
from
MSeifert04:fix_links_collection_docs
Mar 26, 2018
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc1cb5a
Corrected link targets in collections.rst
MSeifert04 6ae77ec
updated according to comments
MSeifert04 40ac948
fixed grammar
MSeifert04 9b48be9
undo line breaks and comment "not-code" example
MSeifert04 e7d12ef
Merge branch 'master' into fix_links_collection_docs
serhiy-storchaka 5957f98
Merge branch 'master' into fix_links_collection_docs
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ The class can be used to simulate nested scopes and is useful in templating. | |
for templating is a read-only chain of mappings. It also features | ||
pushing and popping of contexts similar to the | ||
:meth:`~collections.ChainMap.new_child` method and the | ||
:meth:`~collections.ChainMap.parents` property. | ||
:attr:`~collections.ChainMap.parents` property. | ||
|
||
* The `Nested Contexts recipe | ||
<https://code.activestate.com/recipes/577434/>`_ has options to control | ||
|
@@ -270,7 +270,7 @@ For example:: | |
|
||
Return a list of the *n* most common elements and their counts from the | ||
most common to the least. If *n* is omitted or ``None``, | ||
:func:`most_common` returns *all* elements in the counter. | ||
:meth:`most_common` returns *all* elements in the counter. | ||
Elements with equal counts are ordered arbitrarily: | ||
|
||
>>> Counter('abracadabra').most_common(3) # doctest: +SKIP | ||
|
@@ -357,21 +357,22 @@ or subtracting from an empty counter. | |
restrictions on its keys and values. The values are intended to be numbers | ||
representing counts, but you *could* store anything in the value field. | ||
|
||
* The :meth:`most_common` method requires only that the values be orderable. | ||
* The :meth:`~Counter.most_common` method requires only that the values be | ||
orderable. | ||
|
||
* For in-place operations such as ``c[key] += 1``, the value type need only | ||
support addition and subtraction. So fractions, floats, and decimals would | ||
work and negative values are supported. The same is also true for | ||
:meth:`update` and :meth:`subtract` which allow negative and zero values | ||
for both inputs and outputs. | ||
:meth:`~Counter.update` and :meth:`~Counter.subtract` which allow negative | ||
and zero values for both inputs and outputs. | ||
|
||
* The multiset methods are designed only for use cases with positive values. | ||
The inputs may be negative or zero, but only outputs with positive values | ||
are created. There are no type restrictions, but the value type needs to | ||
support addition, subtraction, and comparison. | ||
|
||
* The :meth:`elements` method requires integer counts. It ignores zero and | ||
negative counts. | ||
* The :meth:`~Counter.elements` method requires integer counts. It ignores | ||
zero and negative counts. | ||
|
||
.. seealso:: | ||
|
||
|
@@ -388,9 +389,9 @@ or subtracting from an empty counter. | |
Section 4.6.3, Exercise 19*. | ||
|
||
* To enumerate all distinct multisets of a given size over a given set of | ||
elements, see :func:`itertools.combinations_with_replacement`: | ||
elements, see :func:`itertools.combinations_with_replacement`:: | ||
|
||
map(Counter, combinations_with_replacement('ABC', 2)) --> AA AB AC BB BC CC | ||
map(Counter, combinations_with_replacement('ABC', 2)) --> AA AB AC BB BC CC | ||
|
||
|
||
:class:`deque` objects | ||
|
@@ -618,19 +619,19 @@ added elements by appending to the right and popping to the left:: | |
d.append(elem) | ||
yield s / n | ||
|
||
The :meth:`rotate` method provides a way to implement :class:`deque` slicing and | ||
deletion. For example, a pure Python implementation of ``del d[n]`` relies on | ||
the :meth:`rotate` method to position elements to be popped:: | ||
The :meth:`~deque.rotate` method provides a way to implement :class:`deque` slicing | ||
and deletion. For example, a pure Python implementation of ``del d[n]`` relies on | ||
the ``rotate()`` method to position elements to be popped:: | ||
|
||
def delete_nth(d, n): | ||
d.rotate(-n) | ||
d.popleft() | ||
d.rotate(n) | ||
|
||
To implement :class:`deque` slicing, use a similar approach applying | ||
:meth:`rotate` to bring a target element to the left side of the deque. Remove | ||
old entries with :meth:`popleft`, add new entries with :meth:`extend`, and then | ||
reverse the rotation. | ||
:meth:`~deque.rotate` to bring a target element to the left side of the deque. | ||
Remove old entries with :meth:`~deque.popleft`, add new entries with | ||
:meth:`~deque.extend`, and then reverse the rotation. | ||
With minor variations on that approach, it is easy to implement Forth style | ||
stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``, | ||
``rot``, and ``roll``. | ||
|
@@ -690,8 +691,8 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``, | |
:class:`defaultdict` Examples | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Using :class:`list` as the :attr:`default_factory`, it is easy to group a | ||
sequence of key-value pairs into a dictionary of lists: | ||
Using :class:`list` as the :attr:`~defaultdict.default_factory`, it is easy to | ||
group a sequence of key-value pairs into a dictionary of lists: | ||
|
||
>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] | ||
>>> d = defaultdict(list) | ||
|
@@ -702,7 +703,7 @@ sequence of key-value pairs into a dictionary of lists: | |
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])] | ||
|
||
When each key is encountered for the first time, it is not already in the | ||
mapping; so an entry is automatically created using the :attr:`default_factory` | ||
mapping; so an entry is automatically created using the :attr:`~defaultdict.default_factory` | ||
function which returns an empty :class:`list`. The :meth:`list.append` | ||
operation then attaches the value to the new list. When keys are encountered | ||
again, the look-up proceeds normally (returning the list for that key) and the | ||
|
@@ -716,7 +717,7 @@ simpler and faster than an equivalent technique using :meth:`dict.setdefault`: | |
>>> sorted(d.items()) | ||
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])] | ||
|
||
Setting the :attr:`default_factory` to :class:`int` makes the | ||
Setting the :attr:`~defaultdict.default_factory` to :class:`int` makes the | ||
:class:`defaultdict` useful for counting (like a bag or multiset in other | ||
languages): | ||
|
||
|
@@ -729,7 +730,7 @@ languages): | |
[('i', 4), ('m', 1), ('p', 2), ('s', 4)] | ||
|
||
When a letter is first encountered, it is missing from the mapping, so the | ||
:attr:`default_factory` function calls :func:`int` to supply a default count of | ||
:attr:`~defaultdict.default_factory` function calls :func:`int` to supply a default count of | ||
zero. The increment operation then builds up the count for each letter. | ||
|
||
The function :func:`int` which always returns zero is just a special case of | ||
|
@@ -744,7 +745,7 @@ zero): | |
>>> '%(name)s %(action)s to %(object)s' % d | ||
'John ran to <missing>' | ||
|
||
Setting the :attr:`default_factory` to :class:`set` makes the | ||
Setting the :attr:`~defaultdict.default_factory` to :class:`set` makes the | ||
:class:`defaultdict` useful for building a dictionary of sets: | ||
|
||
>>> s = [('red', 1), ('blue', 2), ('red', 3), ('blue', 4), ('red', 1), ('blue', 4)] | ||
|
@@ -788,7 +789,7 @@ they add the ability to access fields by name instead of position index. | |
|
||
If *verbose* is true, the class definition is printed after it is | ||
built. This option is outdated; instead, it is simpler to print the | ||
:attr:`_source` attribute. | ||
:attr:`~somenamedtuple._source` attribute. | ||
|
||
If *module* is defined, the ``__module__`` attribute of the named tuple is | ||
set to that value. | ||
|
@@ -938,7 +939,7 @@ The subclass shown above sets ``__slots__`` to an empty tuple. This helps | |
keep memory requirements low by preventing the creation of instance dictionaries. | ||
|
||
Subclassing is not useful for adding new, stored fields. Instead, simply | ||
create a new named tuple type from the :attr:`_fields` attribute: | ||
create a new named tuple type from the :attr:`~somenamedtuple._fields` attribute: | ||
|
||
>>> Point3D = namedtuple('Point3D', Point._fields + ('z',)) | ||
|
||
|
@@ -954,7 +955,7 @@ fields: | |
.. versionchanged:: 3.5 | ||
Property docstrings became writeable. | ||
|
||
Default values can be implemented by using :meth:`_replace` to | ||
Default values can be implemented by using :meth:`~somenamedtuple._replace` to | ||
customize a prototype instance: | ||
|
||
>>> Account = namedtuple('Account', 'owner balance transaction_count') | ||
|
@@ -1165,15 +1166,22 @@ subclass directly from :class:`str`; however, this class can be easier | |
to work with because the underlying string is accessible as an | ||
attribute. | ||
|
||
.. class:: UserString([sequence]) | ||
.. class:: UserString(seq) | ||
|
||
Class that simulates a string or a Unicode string object. The instance's | ||
Class that simulates a string object. The instance's | ||
content is kept in a regular string object, which is accessible via the | ||
:attr:`data` attribute of :class:`UserString` instances. The instance's | ||
contents are initially set to a copy of *sequence*. The *sequence* can | ||
be an instance of :class:`bytes`, :class:`str`, :class:`UserString` (or a | ||
subclass) or an arbitrary sequence which can be converted into a string using | ||
the built-in :func:`str` function. | ||
contents are initially set to a copy of *seq*. The *seq* argument can | ||
be any object which can be converted into a string using the built-in | ||
:func:`str` function. | ||
|
||
In addition to supporting the methods and operations of strings, | ||
:class:`UserString` instances provide the following attribute: | ||
|
||
.. attribute:: data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be added the paragraph "In addition to supporting ..." as for UserDict and UserList? |
||
|
||
A real :class:`str` object used to store the contents of the | ||
:class:`UserString` class. | ||
|
||
.. versionchanged:: 3.5 | ||
New methods ``__getnewargs__``, ``__rmod__``, ``casefold``, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change also
:func:'most_common'
above to:meth:'most_common'
.