Three PEP updates:
* Correct the pure python implementation. * Link to an implementation patch on SF. * Remove the proposed application of __reverse__ to enumerate().
This commit is contained in:
parent
a232b370a0
commit
1ae49ce2cc
17
pep-0322.txt
17
pep-0322.txt
|
@ -67,11 +67,10 @@ reverse iteration is to specify it in a forward direction and then say
|
|||
The implementation could be as simple as::
|
||||
|
||||
def reversed(x):
|
||||
try:
|
||||
return x.__reversed__()
|
||||
except AttributeError:
|
||||
pass
|
||||
if hasattr(x, "has_key"):
|
||||
if hasattr(x, 'reversed'):
|
||||
for elem x.__reversed__():
|
||||
yield x
|
||||
if hasattr(x, 'keys'):
|
||||
raise ValueError("mappings do not support reverse iteration")
|
||||
i = len(x)
|
||||
while i > 0:
|
||||
|
@ -81,6 +80,8 @@ The implementation could be as simple as::
|
|||
No language syntax changes are needed. The proposal is fully backwards
|
||||
compatible.
|
||||
|
||||
A C implementation and unit tests are at: http://www.python.org/sf/834422
|
||||
|
||||
|
||||
Alternative Method Names
|
||||
========================
|
||||
|
@ -102,12 +103,6 @@ This allows *reverse()* to be applied to objects that do not have
|
|||
__getitem__() and __len__() but still have some useful way of
|
||||
providing reverse iteration.
|
||||
|
||||
For example, using this protocol, *enumerate()* can be extended to
|
||||
support reversal whenever the underlying iterator supports it also::
|
||||
|
||||
>>> list(reversed(enumerate("abc")))
|
||||
[(2, 'c'), (1, 'b'), (0, 'a')]
|
||||
|
||||
|
||||
Real World Use Cases
|
||||
====================
|
||||
|
|
Loading…
Reference in New Issue