Commit 3567a876 authored by Raymond Hettinger's avatar Raymond Hettinger

Add take() to examples. Tighten the islice() example

parent 5d2f515d
...@@ -314,7 +314,7 @@ Check 1202 is for $823.14 ...@@ -314,7 +314,7 @@ Check 1202 is for $823.14
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', >>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura',
'', 'martin', '', 'walter', '', 'samuele'] '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, len(reportlines), 2): >>> for name in islice(reportlines, 3, None, 2):
... print name.title() ... print name.title()
... ...
Alex Alex
...@@ -380,4 +380,7 @@ from building blocks. ...@@ -380,4 +380,7 @@ from building blocks.
... result = result[1:] + (elem,) ... result = result[1:] + (elem,)
... yield result ... yield result
>>> def take(n, seq):
... return list(islice(seq, n))
\end{verbatim} \end{verbatim}
...@@ -392,7 +392,7 @@ Check 1202 is for $823.14 ...@@ -392,7 +392,7 @@ Check 1202 is for $823.14
27 27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele'] >>> 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() ... print name.title()
... ...
Alex Alex
...@@ -449,6 +449,9 @@ Samuele ...@@ -449,6 +449,9 @@ Samuele
... result = result[1:] + (elem,) ... result = result[1:] + (elem,)
... yield result ... 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 This is not part of the examples but it tests to make sure the definitions
perform as purported. perform as purported.
...@@ -494,6 +497,9 @@ False ...@@ -494,6 +497,9 @@ False
>>> dotproduct([1,2,3], [4,5,6]) >>> dotproduct([1,2,3], [4,5,6])
32 32
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
""" """
__test__ = {'libreftest' : libreftest} __test__ = {'libreftest' : libreftest}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment