]> granicus.if.org Git - python/commitdiff
Add take() to examples. Tighten the islice() example
authorRaymond Hettinger <python@rcn.com>
Sat, 28 Jun 2003 05:44:36 +0000 (05:44 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 28 Jun 2003 05:44:36 +0000 (05:44 +0000)
Doc/lib/libitertools.tex
Lib/test/test_itertools.py

index e146c6c989c07c670a1273ff9fb7eed1dc8c6d7b..4f025e3c9b70a3d421f0dbd3543018e2e21f5c86 100644 (file)
@@ -314,7 +314,7 @@ Check 1202 is for $823.14
 
 >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
                   '', 'martin', '', 'walter', '', 'samuele']
->>> for name in islice(reportlines, 3, len(reportlines), 2):
+>>> for name in islice(reportlines, 3, None, 2):
 ...    print name.title()
 ...
 Alex
@@ -380,4 +380,7 @@ from building blocks.
 ...         result = result[1:] + (elem,)
 ...         yield result
 
+>>> def take(n, seq):
+...     return list(islice(seq, n))
+
 \end{verbatim}
index 846a690836f88e3045d5481329e334a7aef34fd3..db7e3bdba2ee1d4879de4e76f87c48b69fe888c1 100644 (file)
@@ -392,7 +392,7 @@ Check 1202 is for $823.14
 27
 
 >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
->>> for name in islice(reportlines, 3, len(reportlines), 2):
+>>> for name in islice(reportlines, 3, None, 2):
 ...    print name.title()
 ...
 Alex
@@ -449,6 +449,9 @@ Samuele
 ...         result = result[1:] + (elem,)
 ...         yield result
 
+>>> def take(n, seq):
+...     return list(islice(seq, n))
+
 This is not part of the examples but it tests to make sure the definitions
 perform as purported.
 
@@ -494,6 +497,9 @@ False
 >>> dotproduct([1,2,3], [4,5,6])
 32
 
+>>> take(10, count())
+[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
 """
 
 __test__ = {'libreftest' : libreftest}