Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0cb99d23
Commit
0cb99d23
authored
Jan 06, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1582: document __reversed__, patch by Mark Russell.
parent
8abf0a90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
Doc/ACKS.txt
Doc/ACKS.txt
+1
-0
Doc/library/functions.rst
Doc/library/functions.rst
+7
-3
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+16
-0
No files found.
Doc/ACKS.txt
View file @
0cb99d23
...
...
@@ -158,6 +158,7 @@ docs@python.org), and we'll be glad to correct the problem.
* Jim Roskind
* Guido van Rossum
* Donald Wallace Rouse II
* Mark Russell
* Nick Russo
* Chris Ryland
* Constantina S.
...
...
Doc/library/functions.rst
View file @
0cb99d23
...
...
@@ -977,12 +977,16 @@ available. They are listed here in alphabetical order.
.. function:: reversed(seq)
Return a reverse :term:`iterator`. *seq* must be an object which supports
the sequence protocol (the :meth:`__len__` method and the :meth:`__getitem__`
method with integer arguments starting at ``0``).
Return a reverse :term:`iterator`. *seq* must be an object which has
a :meth:`__reversed__` method or supports the sequence protocol (the
:meth:`__len__` method and the :meth:`__getitem__` method with integer
arguments starting at ``0``).
.. versionadded:: 2.4
.. versionchanged:: 2.6
Added the possibility to write a custom :meth:`__reversed__` method.
.. function:: round(x[, n])
...
...
Doc/reference/datamodel.rst
View file @
0cb99d23
...
...
@@ -1796,6 +1796,22 @@ sequences, it should iterate through the values.
Iterator objects also need to implement this method; they are required to return
themselves. For more information on iterator objects, see :ref:`typeiter`.
.. method:: object.__reversed__(self)
Called (if present) by the :func:`reversed` builtin to implement
reverse iteration. It should return a new iterator object that iterates
over all the objects in the container in reverse order.
If the :meth:`__reversed__` method is not provided, the
:func:`reversed` builtin will fall back to using the sequence protocol
(:meth:`__len__` and :meth:`__getitem__`). Objects should normally
only provide :meth:`__reversed__` if they do not support the sequence
protocol and an efficient implementation of reverse iteration is possible.
.. versionadded:: 2.6
The membership test operators (:keyword:`in` and :keyword:`not in`) are normally
implemented as an iteration through a sequence. However, container objects can
supply the following special method with a more efficient implementation, which
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment