Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fdf3bd66
Commit
fdf3bd66
authored
Mar 27, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF patch #1171417: bug fix for islice() in docs
parent
267b868f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
Doc/lib/libitertools.tex
Doc/lib/libitertools.tex
+7
-9
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+5
-0
No files found.
Doc/lib/libitertools.tex
View file @
fdf3bd66
...
...
@@ -250,16 +250,14 @@ by functions or loops that truncate the stream.
third line). Equivalent to:
\begin{verbatim}
def islice(iterable, *args):
def islice(iterable, *args):
s = slice(*args)
next, stop, step = s.start or 0, s.stop, s.step or 1
for cnt, element in enumerate(iterable):
if cnt < next:
continue
if stop is not None and cnt >= stop:
break
yield element
next += step
it = iter(xrange(s.start or 0, s.stop or sys.maxint, s.step or 1))
nexti = it.next()
for i, element in enumerate(iterable):
if i == nexti:
yield element
nexti = it.next()
\end{verbatim}
If
\var
{
start
}
is
\code
{
None
}
, then iteration starts at zero.
...
...
Lib/test/test_itertools.py
View file @
fdf3bd66
...
...
@@ -265,6 +265,11 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
list
(
islice
(
xrange
(
10
),
2
,
None
)),
range
(
2
,
10
))
self
.
assertEqual
(
list
(
islice
(
xrange
(
10
),
1
,
None
,
2
)),
range
(
1
,
10
,
2
))
# Test number of items consumed SF #1171417
it
=
iter
(
range
(
10
))
self
.
assertEqual
(
list
(
islice
(
it
,
3
)),
range
(
3
))
self
.
assertEqual
(
list
(
it
),
range
(
3
,
10
))
# Test invalid arguments
self
.
assertRaises
(
TypeError
,
islice
,
xrange
(
10
))
self
.
assertRaises
(
TypeError
,
islice
,
xrange
(
10
),
1
,
2
,
3
,
4
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment