[Python-checkins] python/nondist/sandbox/itertools libitertools.tex,1.8,1.9

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Mon, 27 Jan 2003 07:43:29 -0800


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

Modified Files:
	libitertools.tex 
Log Message:
Transform the pure python versions from off-the-cuff psuedo-code into
tested executable code.


Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/libitertools.tex,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** libitertools.tex	27 Jan 2003 12:16:42 -0000	1.8
--- libitertools.tex	27 Jan 2003 15:42:54 -0000	1.9
***************
*** 96,101 ****
    \begin{verbatim}
       def count(n=0):
           while True:
!              yield n
               cnt += 1
    \end{verbatim}
--- 96,102 ----
    \begin{verbatim}
       def count(n=0):
+          cnt = n
           while True:
!              yield cnt
               cnt += 1
    \end{verbatim}
***************
*** 108,112 ****
  
    \begin{verbatim}
!      def dropwhile(func, iterable, invert=False):
           iterable = iter(iterable)
           while True:
--- 109,113 ----
  
    \begin{verbatim}
!      def dropwhile(predicate, iterable, invert=False):
           iterable = iter(iterable)
           while True:
***************
*** 128,137 ****
  
    \begin{verbatim}
!      def filter(func, iterable, invert=False):
           iterable = iter(iterable)
           while True:
!              x = bool(iterable.next())
!              if not invert and x or invert and not x:
!                  yield None
    \end{verbatim}
  \end{funcdesc}
--- 129,139 ----
  
    \begin{verbatim}
!      def ifilter(func, iterable, invert=False):
           iterable = iter(iterable)
           while True:
!              x = iterable.next()
!              b = bool(func(x))
!              if not invert and b or invert and not b:
!                  yield x
    \end{verbatim}
  \end{funcdesc}
***************
*** 150,154 ****
           while True:
               args = [i.next() for i in iterables]
!              yield f(*args)
    \end{verbatim}
  \end{funcdesc}
--- 152,156 ----
           while True:
               args = [i.next() for i in iterables]
!              yield func(*args)
    \end{verbatim}
  \end{funcdesc}
***************
*** 192,196 ****
           while True:
               for i in xrange(len(iterables)):
!                  result[i] = iterable[i].next()
               yield result
    \end{verbatim}
--- 194,198 ----
           while True:
               for i in xrange(len(iterables)):
!                  result[i] = iterables[i].next()
               yield result
    \end{verbatim}
***************
*** 205,209 ****
       def repeat(x):
           while True:
!              yield None
    \end{verbatim}
  \end{funcdesc}
--- 207,211 ----
       def repeat(x):
           while True:
!              yield x
    \end{verbatim}
  \end{funcdesc}
***************
*** 214,218 ****
  
    \begin{verbatim}
!      def stapmap(func, iterable):
           iterable = iter(iterable)
           while True:
--- 216,220 ----
  
    \begin{verbatim}
!      def starmap(func, iterable):
           iterable = iter(iterable)
           while True:
***************
*** 226,230 ****
  
    \begin{verbatim}
!      def takewhile(func, iterable, invert=False):
           iterable = iter(iterable)
           while True:
--- 228,232 ----
  
    \begin{verbatim}
!      def takewhile(predicate, iterable, invert=False):
           iterable = iter(iterable)
           while True:
***************
*** 244,247 ****
--- 246,250 ----
    \begin{verbatim}
       def times(n):
+          if n<0: raise ValueError
           for i in xrange(n):
               yield None