]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Adopt Christian Stork's suggested argument order for quantifier examples.
authorRaymond Hettinger <python@rcn.com>
Sun, 5 Oct 2003 23:05:56 +0000 (23:05 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 5 Oct 2003 23:05:56 +0000 (23:05 +0000)
Adopt Jeremy Fincher's suggested function name, "any", instead of "some".

Doc/lib/libitertools.tex
Lib/test/test_itertools.py

index c68e6af7715bac0ba6132513863290b5a2f2cd8e..dc1a77c39c8c2082f59c1dcfdb076ccb26c37e7b 100644 (file)
@@ -344,19 +344,19 @@ def nth(iterable, n):
     "Returns the nth item"
     return list(islice(iterable, n, n+1))
 
-def all(pred, seq):
+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 some(pred, seq):
+def any(seq, pred=bool):
     "Returns True if pred(x) is True at least one element in the iterable"
     return True in imap(pred, seq)
 
-def no(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(pred, seq):
+def quantify(seq, pred=bool):
     "Count how many times the predicate is True in the sequence"
     return sum(imap(pred, seq))
 
index 3f6c9d258d53011666d7504f59b45520a36de403..2da82ed9c77bca639d116fe4c9fed72c7ba08b14 100644 (file)
@@ -501,19 +501,19 @@ Samuele
 ...     "Returns the nth item"
 ...     return list(islice(iterable, n, n+1))
 
->>> def all(pred, seq):
+>>> 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 some(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(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(pred, seq):
+>>> def quantify(seq, pred=bool):
 ...     "Count how many times the predicate is True in the sequence"
 ...     return sum(imap(pred, seq))
 
@@ -554,25 +554,25 @@ perform as purported.
 >>> nth('abcde', 3)
 ['d']
 
->>> all(lambda x: x%2==0, [2, 4, 6, 8])
+>>> all([2, 4, 6, 8], lambda x: x%2==0)
 True
 
->>> all(lambda x: x%2==0, [2, 3, 6, 8])
+>>> all([2, 3, 6, 8], lambda x: x%2==0)
 False
 
->>> some(lambda x: x%2==0, [2, 4, 6, 8])
+>>> any([2, 4, 6, 8], lambda x: x%2==0)
 True
 
->>> some(lambda x: x%2==0, [1, 3, 5, 9])
+>>> any([1, 3, 5, 9], lambda x: x%2==0,)
 False
 
->>> no(lambda x: x%2==0, [1, 3, 5, 9])
+>>> no([1, 3, 5, 9], lambda x: x%2==0)
 True
 
->>> no(lambda x: x%2==0, [1, 2, 5, 9])
+>>> no([1, 2, 5, 9], lambda x: x%2==0)
 False
 
->>> quantify(lambda x: x%2==0, xrange(99))
+>>> quantify(xrange(99), lambda x: x%2==0)
 50
 
 >>> list(window('abc'))