[Python-checkins] peps: BDFL pronouncements.
georg.brandl
python-checkins at python.org
Wed Mar 23 21:23:50 CET 2011
http://hg.python.org/peps/rev/8cd249c174a0
changeset: 59:8cd249c174a0
user: Guido van Rossum <guido at python.org>
date: Thu Jul 27 20:13:39 2000 +0000
summary:
BDFL pronouncements.
Got rid of ^L.
files:
pep-0202.txt | 33 +++++++++++++++++++++++----------
1 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/pep-0202.txt b/pep-0202.txt
--- a/pep-0202.txt
+++ b/pep-0202.txt
@@ -5,14 +5,14 @@
Python-Version: 2.0
Status: Incomplete
-
+
Introduction
This PEP describes a proposed syntactical extension to Python, list
comprehensions.
-
+
The Proposed Solution
It is proposed to allow conditional construction of list literals using
@@ -20,14 +20,14 @@
statements nest now.
-
+
Rationale
List comprehensions provide a more concise way to create lists in
situations where map() and filter() and/or nested loops would currently
be used.
-
+
Examples
>>> print [i for i in range(10)]
@@ -38,17 +38,17 @@
>>> nums = [1,2,3,4]
>>> fruit = ["Apples", "Peaches", "Pears", "Bananas"]
- >>> print [i,f for i in nums for f in fruit]
+ >>> print [(i,f) for i in nums for f in fruit]
[(1, 'Apples'), (1, 'Peaches'), (1, 'Pears'), (1, 'Bananas'),
(2, 'Apples'), (2, 'Peaches'), (2, 'Pears'), (2, 'Bananas'),
(3, 'Apples'), (3, 'Peaches'), (3, 'Pears'), (3, 'Bananas'),
(4, 'Apples'), (4, 'Peaches'), (4, 'Pears'), (4, 'Bananas')]
- >>> print [i,f for i in nums for f in fruit if f[0] == "P"]
+ >>> print [(i,f) for i in nums for f in fruit if f[0] == "P"]
[(1, 'Peaches'), (1, 'Pears'),
(2, 'Peaches'), (2, 'Pears'),
(3, 'Peaches'), (3, 'Pears'),
(4, 'Peaches'), (4, 'Pears')]
- >>> print [i,f for i in nums for f in fruit if f[0] == "P" if i%2 == 1]
+ >>> print [(i,f) for i in nums for f in fruit if f[0] == "P" if i%2 == 1]
[(1, 'Peaches'), (1, 'Pears'), (3, 'Peaches'), (3, 'Pears')]
>>> def zip(*args):
... return apply(map, (None,)+args)
@@ -56,7 +56,7 @@
>>> print [i for i in zip(nums,fruit) if i[0]%2==0]
[(2, 'Peaches'), (4, 'Bananas')]
-
+
Reference Implementation
Please refer to
@@ -66,7 +66,20 @@
for a patch that adds list comprehensions to Python.
-
+BDFL Pronouncements
+
+ Note: the BDFL refers to Guido van Rossum, Python's Benevolent
+ Dictator For Life.
+
+ - The syntax proposed above is the Right One.
+
+ - The form [x, y for ...] should be disallowed; one should be
+ required to write [(x, y) for ...].
+
+ - The form [... for x... for y...] nests, with the last index
+ varying fastest, just like nested for loops.
+
+
Open Issues
Syntax
@@ -113,7 +126,7 @@
is. It has not had a lot of exercise, though the patch does include
a few test cases.
-
+
Local Variables:
mode: indented-text
indent-tabs-mode: nil
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list