[Python-checkins] r46606 - sandbox/trunk/Doc/functional.rst

andrew.kuchling python-checkins at python.org
Sat Jun 3 03:45:30 CEST 2006


Author: andrew.kuchling
Date: Sat Jun  3 03:45:26 2006
New Revision: 46606

Modified:
   sandbox/trunk/Doc/functional.rst
Log:
Add some incomplete text and some XXX markers

Modified: sandbox/trunk/Doc/functional.rst
==============================================================================
--- sandbox/trunk/Doc/functional.rst	(original)
+++ sandbox/trunk/Doc/functional.rst	Sat Jun  3 03:45:26 2006
@@ -597,6 +597,49 @@
 many different points (the ``yield`` statements).  
 
 
+Built-in functions
+----------------------------------------------
+
+Let's look in more detail at those built-in functions that are
+relevant to iterators.
+
+any(), all()
+
+enumerate()
+
+sorted()
+
+sum()
+
+Two Python's built-in functions, ``map()`` and ``filter()``, are
+somewhat obsolete; they duplicate the features of list comprehensions
+and return actual lists instead of iterators.  
+
+``map(f, iterA, iterB, ...)`` returns a list containing ``f(iterA[0],
+iterB[0]), f(iterA[1], iterB[1]), f(iterA[2], iterB[2]), ...``.  
+
+::
+
+    def upper(s):
+        return s.upper()
+    map(upper, ['sentence', 'fragment']) =>
+      ['SENTENCE', 'FRAGMENT']
+
+    [upper(s) for s in ['sentence', 'fragment']] =>
+      ['SENTENCE', 'FRAGMENT']
+
+As shown above, you can achieve the same effect with a list
+comprehension.  The ``itertools.imap()`` function does the same thing
+but can handle infinite iterators; it'll be discussed in the section on 
+the ``itertools`` module.
+
+``filter(predicate, iter)`` is similarly duplicated by list comprehensions. 
+**, a function that returns the truth value of
+some condition.  
+
+reduce()
+
+
 The itertools module
 -----------------------
 
@@ -726,8 +769,7 @@
       /usr/bin/java, /bin/python, /usr/bin/perl, /usr/bin/ruby
 
 Another group of functions chooses a subset of an iterator's elements
-based on a **predicate**, a function that returns the truth value of
-some condition.  
+based on a predicate.
 
 ``itertools.ifilter(predicate, iter)`` returns all the elements for
 which the predicate returns true::
@@ -812,12 +854,6 @@
 of iterator-1 before requesting iterator-2 and its corresponding key.
 
 
-Built-in functions
-----------------------------------------------
-
-map(), filter(), reduce()
-os.walk()
-
 Small functions and the lambda statement
 ----------------------------------------------
 
@@ -826,6 +862,18 @@
 The functools module
 ----------------------------------------------
 
+XXX
+
+Topics to place
+-----------------------------
+
+XXX
+
+os.walk()
+
+Need a large example.
+
+=======
 
 Acknowledgements
 ------------------------------


More information about the Python-checkins mailing list