Fixed a typo in my email address.
Updated 'Loop counter iteration' PEP 212.
This commit is contained in:
parent
4be092d93e
commit
cc08f77942
|
@ -159,7 +159,7 @@ Owners
|
|||
Raymond, Eric esr@snark.thyrsus.com
|
||||
van Rossum, Guido guido@python.org
|
||||
Schemenauer, Neil nas@arctrix.com
|
||||
Schneider-Kamp, Peter nownder@nowonder.de
|
||||
Schneider-Kamp, Peter nowonder@nowonder.de
|
||||
Warsaw, Barry barry@digicool.com
|
||||
Wilson, Greg gvwilson@nevex.com
|
||||
Wouters, Thomas thomas@xs4all.net
|
||||
|
|
58
pep-0212.txt
58
pep-0212.txt
|
@ -4,8 +4,8 @@ Version: $Revision$
|
|||
Author: nowonder@nowonder.de (Peter Schneider-Kamp)
|
||||
Status: Draft
|
||||
Type: Standards Track
|
||||
Python-Version: 2.1
|
||||
Created: 22-Aug-2000
|
||||
Python-Version: 2.1
|
||||
|
||||
|
||||
Introduction
|
||||
|
@ -52,13 +52,9 @@ Loop counter iteration
|
|||
|
||||
The Proposed Solutions
|
||||
|
||||
There are two solutions that have been discussed. One adds a
|
||||
There are three solutions that have been discussed. One adds a
|
||||
non-reserved keyword, the other adds two built-in functions.
|
||||
|
||||
A third solution would have been the addition of 'keys', 'items'
|
||||
and 'values' methods to sequences, which enable looping over
|
||||
indices only, both indices and elements, and elements only
|
||||
respectively.
|
||||
A third solution adds methods to sequence objects.
|
||||
|
||||
|
||||
Non-reserved keyword 'indexing'
|
||||
|
@ -103,6 +99,51 @@ Built-in functions 'indices' and 'irange'
|
|||
# work with index i and element e
|
||||
|
||||
|
||||
Methods for sequence objects
|
||||
|
||||
This solution proposes the addition of 'indices', 'items'
|
||||
and 'values' methods to sequences, which enable looping over
|
||||
indices only, both indices and elements, and elements only
|
||||
respectively.
|
||||
|
||||
This would immensely simplify the idioms for looping over indices
|
||||
and for looping over both elements and indices:
|
||||
|
||||
for i in sequence.indices():
|
||||
# work with index i
|
||||
|
||||
for i, e in sequence.items():
|
||||
# work with index i and element e
|
||||
|
||||
Additionally it would allow to do looping over the elements
|
||||
of sequences and dicitionaries in a consistent way:
|
||||
|
||||
for e in sequence_or_dict.values():
|
||||
# do something with element e
|
||||
|
||||
|
||||
Implementations
|
||||
|
||||
For all three solutions some more or less rough patches exist
|
||||
as patches at SourceForge:
|
||||
|
||||
'for i indexing a in l': exposing the for-loop counter[3]
|
||||
add indices() and irange() to built-ins[4]
|
||||
add items() method to listobject[5]
|
||||
|
||||
All of them have been pronounced on and rejected by the BDFL.
|
||||
|
||||
Note that the 'indexing' keyword is only a NAME in the
|
||||
grammar and so does not hinder the general use of 'indexing'.
|
||||
|
||||
|
||||
Backward Compatibility Issues
|
||||
|
||||
As no keywords are added and the semantics of existing code
|
||||
remains unchanged, all three solutions can be implemented
|
||||
without breaking existing code.
|
||||
|
||||
|
||||
Copyright
|
||||
|
||||
This document has been placed in the public domain.
|
||||
|
@ -112,6 +153,9 @@ References
|
|||
|
||||
[1] http://www.python.org/doc/current/ref/for.html
|
||||
[2] Lockstep Iteration, pep-0201.txt
|
||||
[3] http://sourceforge.net/patch/download.php?id=101138
|
||||
[4] http://sourceforge.net/patch/download.php?id=101129
|
||||
[5] http://sourceforge.net/patch/download.php?id=101178
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue