[Python-checkins] python/dist/src/Lib/test test_itertools.py, 1.20,
1.21
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Oct 5 12:47:38 EDT 2003
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv10364/Lib/test
Modified Files:
test_itertools.py
Log Message:
Adopt Christian Stork's suggested argument order for the logic quantifiers.
Adopt Jeremy Fincher's suggested function name, "any", instead of "some".
Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** test_itertools.py 13 Sep 2003 01:01:34 -0000 1.20
--- test_itertools.py 5 Oct 2003 16:47:36 -0000 1.21
***************
*** 505,521 ****
... return list(islice(iterable, n, n+1))
! >>> def all(pred, seq):
... "Returns True if pred(x) is True for every element in the iterable"
... return False not in imap(pred, seq)
! >>> def some(pred, seq):
... "Returns True if pred(x) is True for at least one element in the iterable"
... return True in imap(pred, seq)
! >>> def no(pred, seq):
... "Returns True if pred(x) is False for every element in the iterable"
... return True not in imap(pred, seq)
! >>> def quantify(pred, seq):
... "Count how many times the predicate is True in the sequence"
... return sum(imap(pred, seq))
--- 505,521 ----
... return list(islice(iterable, n, n+1))
! >>> def all(seq, pred=bool):
... "Returns True if pred(x) is True for every element in the iterable"
... return False not in imap(pred, seq)
! >>> def any(seq, pred=bool):
... "Returns True if pred(x) is True for at least one element in the iterable"
... return True in imap(pred, seq)
! >>> def no(seq, pred=bool):
... "Returns True if pred(x) is False for every element in the iterable"
... return True not in imap(pred, seq)
! >>> def quantify(seq, pred=bool):
... "Count how many times the predicate is True in the sequence"
... return sum(imap(pred, seq))
***************
*** 572,594 ****
['d']
! >>> all(lambda x: x%2==0, [2, 4, 6, 8])
True
! >>> all(lambda x: x%2==0, [2, 3, 6, 8])
False
! >>> some(lambda x: x%2==0, [2, 4, 6, 8])
True
! >>> some(lambda x: x%2==0, [1, 3, 5, 9])
False
! >>> no(lambda x: x%2==0, [1, 3, 5, 9])
True
! >>> no(lambda x: x%2==0, [1, 2, 5, 9])
False
! >>> quantify(lambda x: x%2==0, xrange(99))
50
--- 572,594 ----
['d']
! >>> all([2, 4, 6, 8], lambda x: x%2==0)
True
! >>> all([2, 3, 6, 8], lambda x: x%2==0)
False
! >>> any([2, 4, 6, 8], lambda x: x%2==0)
True
! >>> any([1, 3, 5, 9], lambda x: x%2==0,)
False
! >>> no([1, 3, 5, 9], lambda x: x%2==0)
True
! >>> no([1, 2, 5, 9], lambda x: x%2==0)
False
! >>> quantify(xrange(99), lambda x: x%2==0)
50
More information about the Python-checkins
mailing list