[Python-checkins] python/nondist/sandbox/itertools libitertools.tex,1.14,1.15 test_itertools.py,1.10,1.11

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Wed, 29 Jan 2003 11:08:10 -0800


Update of /cvsroot/python/python/nondist/sandbox/itertools
In directory sc8-pr-cvs1:/tmp/cvs-serv13478

Modified Files:
	libitertools.tex test_itertools.py 
Log Message:
Expand documentation to indicate when each tools would be used.
Used spelled-out variable names instead of abbreviations (for clarity).


Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/libitertools.tex,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** libitertools.tex	29 Jan 2003 01:52:04 -0000	1.14
--- libitertools.tex	29 Jan 2003 19:08:07 -0000	1.15
***************
*** 44,48 ****
  
      \item Whether cast in pure python form or C code, tools that use iterators
!         are more memory efficient than their list based counterparts.
          Adopting the principles of just-in-time manufacturing, they create
          data when and where needed instead of consuming memory with the
--- 44,48 ----
  
      \item Whether cast in pure python form or C code, tools that use iterators
!         are more memory efficient (and faster) than their list based counterparts.
          Adopting the principles of just-in-time manufacturing, they create
          data when and where needed instead of consuming memory with the
***************
*** 70,74 ****
  \begin{funcdesc}{count}{\optional{n}}
    Make an iterator that returns consecutive integers starting with \var{n}.
!   Used in zip and loop constructions to consecutively number a sequence.
    Equivalent to:
  
--- 70,75 ----
  \begin{funcdesc}{count}{\optional{n}}
    Make an iterator that returns consecutive integers starting with \var{n}.
!   Often used as a argument to \function{imap()} to generate consecutive
!   data points.  Also, used in \function{izip()} to add sequence numbers.
    Equivalent to:
  
***************
*** 100,122 ****
  \end{funcdesc}
  
! \begin{funcdesc}{ifilter}{func, iterable \optional{, invert}}
    Make an iterator that filters elements from iterable returning only
!   those for which the function evaluates to \code{True}.  If \var{invert}
!   is \code{True}, then reverse the process and pass through only those
!   elements for which the function evaluates to \code{False}.
!   If function is \code{None}, return the items that are true (unless
!   \var{invert} is set).
! 
!   Equivalent to:
  
    \begin{verbatim}
!      def ifilter(func, iterable, invert=False):
           iterable = iter(iterable)
           while True:
               x = iterable.next()
!              if func is None:
                    b = bool(x)
               else:
!                   b = bool(func(x))
               if not invert and b or invert and not b:
                   yield x
--- 101,121 ----
  \end{funcdesc}
  
! \begin{funcdesc}{ifilter}{predicate, iterable \optional{, invert}}
    Make an iterator that filters elements from iterable returning only
!   those for which the predicate function evaluates to \code{True}.  If
!   \var{invert} is \code{True}, then reverse the process and pass through
!   only those elements for which the function evaluates to \code{False}.
!   If \var{predicate} is \code{None}, return the items that are true
!   (or false if \var{invert} has been set).  Equivalent to:
  
    \begin{verbatim}
!      def ifilter(predicate, iterable, invert=False):
           iterable = iter(iterable)
           while True:
               x = iterable.next()
!              if predicate is None:
                    b = bool(x)
               else:
!                   b = bool(predicate(x))
               if not invert and b or invert and not b:
                   yield x
***************
*** 124,130 ****
  \end{funcdesc}
  
! \begin{funcdesc}{imap}{func, *iterables}
    Make an iterator that computes the function using arguments from
!   each of the iterables.  If \var{func} is set to \code{None}, then
    \function{imap()} returns the arguments as a tuple.  Like
    \function{map()} except that it returns an iterator instead of a
--- 123,129 ----
  \end{funcdesc}
  
! \begin{funcdesc}{imap}{function, *iterables}
    Make an iterator that computes the function using arguments from
!   each of the iterables.  If \var{function} is set to \code{None}, then
    \function{imap()} returns the arguments as a tuple.  Like
    \function{map()} except that it returns an iterator instead of a
***************
*** 134,145 ****
  
    \begin{verbatim}
!      def imap(func, *iterables):
           iterables = map(iter, iterables)
           while True:
               args = [i.next() for i in iterables]
!              if func is None:
                   yield tuple(args)
               else:
!                  yield func(*args)
    \end{verbatim}
  \end{funcdesc}
--- 133,144 ----
  
    \begin{verbatim}
!      def imap(function, *iterables):
           iterables = map(iter, iterables)
           while True:
               args = [i.next() for i in iterables]
!              if function is None:
                   yield tuple(args)
               else:
!                  yield function(*args)
    \end{verbatim}
  \end{funcdesc}
***************
*** 154,158 ****
    until the iterable is exhausted.  Unlike regular slicing,
    \function{islice()} does not support negative values for \var{start},
!   \var{stop}, or \var{step}.  Equivalent to:
  
    \begin{verbatim}
--- 153,160 ----
    until the iterable is exhausted.  Unlike regular slicing,
    \function{islice()} does not support negative values for \var{start},
!   \var{stop}, or \var{step}.  Can be used to extract related fields
!   from data where the internal structure has been flattened (for
!   example, a multi-line report may list a name field on every
!   third line).  Equivalent to:
  
    \begin{verbatim}
***************
*** 179,183 ****
    Make an iterator that aggregates elements from each of the iterables.
    Like \function{zip()} except that it returns an iterator instead of
!   a list.  Equivalent to:
  
    \begin{verbatim}
--- 181,186 ----
    Make an iterator that aggregates elements from each of the iterables.
    Like \function{zip()} except that it returns an iterator instead of
!   a list.  Used for lock-step iteration over several iterables at a
!   time.  Equivalent to:
  
    \begin{verbatim}
***************
*** 192,197 ****
  \begin{funcdesc}{repeat}{obj}
    Make an iterator that returns \var{obj} over and over again.
!   Used inside map, zip, or loop constructions for multiple
!   references to the same object.  Equivalent to:
  
    \begin{verbatim}
--- 195,201 ----
  \begin{funcdesc}{repeat}{obj}
    Make an iterator that returns \var{obj} over and over again.
!   Used as argument to \function{imap()} for invariant parameters
!   to the called function.  Also used with function{izip()} to create
!   an invariant part of a tuple record.  Equivalent to:
  
    \begin{verbatim}
***************
*** 202,208 ****
  \end{funcdesc}
  
! \begin{funcdesc}{starmap}{func, iterable}
    Make an iterator that computes the function using arguments tuples
!   obtained from the iterable.  Equivalent to:
  
    \begin{verbatim}
--- 206,217 ----
  \end{funcdesc}
  
! \begin{funcdesc}{starmap}{function, iterable}
    Make an iterator that computes the function using arguments tuples
!   obtained from the iterable.  Used instead of \function{imap()} when
!   argument parameters are already grouped in tuples from a single iterable
!   (the data has been ``pre-zipped'').  The difference between
!   \function{imap()} and \function{starmap} parallels the distinction
!   between \code{function(a,b)} and \code{function(*c)}.
!   Equivalent to:
  
    \begin{verbatim}
***************
*** 257,260 ****
--- 266,270 ----
  Hello
  
+ >>> amounts = [120.15, 764.05, 823.14]
  >>> for checknum, amount in izip(count(1200), amounts):
  ...     print 'Check %d is for $%.2f' % (checknum, amount)
***************
*** 272,278 ****
  27
  
! >>> reportfile = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
                    '', 'martin', '', 'walter', '', 'samuele']
! >>> for name in islice(reportfile, 3, len(reportfile), 2):
  ...    print name.title()
  ...
--- 282,288 ----
  27
  
! >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
                    '', 'martin', '', 'walter', '', 'samuele']
! >>> for name in islice(reportlines, 3, len(reportlines), 2):
  ...    print name.title()
  ...

Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/test_itertools.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_itertools.py	29 Jan 2003 01:52:04 -0000	1.10
--- test_itertools.py	29 Jan 2003 19:08:08 -0000	1.11
***************
*** 108,113 ****
  27
  
! >>> reportfile = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
! >>> for name in islice(reportfile, 3, len(reportfile), 2):
  ...    print name.title()
  ...
--- 108,113 ----
  27
  
! >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
! >>> for name in islice(reportlines, 3, len(reportlines), 2):
  ...    print name.title()
  ...