[Python-checkins] python/nondist/sandbox/itertools libitertools.tex,1.12,1.13 test_itertools.py,1.8,1.9
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Mon, 27 Jan 2003 18:02:29 -0800
Update of /cvsroot/python/python/nondist/sandbox/itertools
In directory sc8-pr-cvs1:/tmp/cvs-serv24656
Modified Files:
libitertools.tex test_itertools.py
Log Message:
Sync-up python definition of ifilter() with the C definition. Make the
related docstrings match and added a test for the case where func is None.
Fixed spelling in docs.
Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/libitertools.tex,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** libitertools.tex 28 Jan 2003 01:05:29 -0000 1.12
--- libitertools.tex 28 Jan 2003 02:02:25 -0000 1.13
***************
*** 23,27 ****
For instance, SML provides a tabulation tool: \code{tabulate(\var{f})}
which produces a sequence \code{f(0), f(1), ...}. This toolbox
! takes a diffenct approach of providing \function{imap()} and
\function{count()} which can be combined to form
\code{imap(\var{f}, count())} and produce an equivalent result.
--- 23,27 ----
For instance, SML provides a tabulation tool: \code{tabulate(\var{f})}
which produces a sequence \code{f(0), f(1), ...}. This toolbox
! takes a different approach of providing \function{imap()} and
\function{count()} which can be combined to form
\code{imap(\var{f}, count())} and produce an equivalent result.
***************
*** 34,38 ****
loops over the sequence elements and then starts again when the
sequence is exhausted. The surprising behavior is the need for
! significant auxilliary storage (unusual for iterators). Also, it
is trivially implemented in python with almost no performance
penalty.
--- 34,38 ----
loops over the sequence elements and then starts again when the
sequence is exhausted. The surprising behavior is the need for
! significant auxiliary storage (unusual for iterators). Also, it
is trivially implemented in python with almost no performance
penalty.
***************
*** 105,108 ****
--- 105,111 ----
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:
***************
*** 112,116 ****
while True:
x = iterable.next()
! b = bool(func(x))
if not invert and b or invert and not b:
yield x
--- 115,122 ----
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
***************
*** 141,145 ****
\begin{funcdesc}{islice}{iterable, \optional{start,} stop \optional{, step}}
Make an iterator that returns selected elements from the iterable.
! If \var{start} is non-zero, then elements from the iterable are skiped
until start is reached. Afterward, elements are returned consecutively
unless \var{step} is set higher than one which results in items being
--- 147,151 ----
\begin{funcdesc}{islice}{iterable, \optional{start,} stop \optional{, step}}
Make an iterator that returns selected elements from the iterable.
! If \var{start} is non-zero, then elements from the iterable are skipped
until start is reached. Afterward, elements are returned consecutively
unless \var{step} is set higher than one which results in items being
Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/test_itertools.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_itertools.py 28 Jan 2003 01:05:29 -0000 1.8
--- test_itertools.py 28 Jan 2003 02:02:26 -0000 1.9
***************
*** 14,17 ****
--- 14,18 ----
self.assertEqual(list(ifilter(isEven, range(6))), [0,2,4])
self.assertEqual(list(ifilter(isEven, range(6), True)), [1,3,5])
+ self.assertEqual(list(ifilter(None, [0,1,0,2,0])), [1,2])
self.assertRaises(TypeError, ifilter)
self.assertRaises(TypeError, ifilter, 3)