Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
3adaa1a9
Commit
3adaa1a9
authored
Jan 11, 2017
by
iury
Committed by
Dylan Trotter
Jan 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make itertools.chain be a class and from_iterable a classmethod of chain
parent
d9af1564
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
lib/itertools.py
lib/itertools.py
+14
-9
lib/itertools_test.py
lib/itertools_test.py
+12
-1
No files found.
lib/itertools.py
View file @
3adaa1a9
...
...
@@ -17,10 +17,20 @@
import
_collections
import
sys
def
chain
(
*
iterables
):
for
it
in
iterables
:
for
element
in
it
:
yield
element
class
chain
(
object
):
def
from_iterable
(
cls
,
iterable
):
return
cls
(
*
iterable
)
from_iterable
=
classmethod
(
from_iterable
)
def
__init__
(
self
,
*
iterables
):
self
.
iterables
=
iterables
def
__iter__
(
self
):
for
it
in
self
.
iterables
:
for
element
in
it
:
yield
element
def
compress
(
data
,
selectors
):
return
(
d
for
d
,
s
in
izip
(
data
,
selectors
)
if
s
)
...
...
@@ -49,11 +59,6 @@ def dropwhile(predicate, iterable):
for
x
in
iterable
:
yield
x
def
from_iterable
(
iterables
):
for
it
in
iterables
:
for
element
in
it
:
yield
element
def
ifilter
(
predicate
,
iterable
):
if
predicate
is
None
:
predicate
=
bool
...
...
lib/itertools_test.py
View file @
3adaa1a9
...
...
@@ -46,6 +46,17 @@ def TestDropwhile():
got
=
tuple
(
itertools
.
dropwhile
(
*
args
))
assert
got
==
want
,
'tuple(dropwhile%s) == %s, want %s'
%
(
args
,
got
,
want
)
def
TestChain
():
r
=
range
(
10
)
cases
=
[
([
r
],
tuple
(
r
)),
([
r
,
r
],
tuple
(
r
)
+
tuple
(
r
)),
([],
())
]
for
args
,
want
in
cases
:
got
=
tuple
(
itertools
.
chain
(
*
args
))
assert
got
==
want
,
'tuple(chain%s) == %s, want %s'
%
(
args
,
got
,
want
)
def
TestFromIterable
():
r
=
range
(
10
)
cases
=
[
...
...
@@ -54,7 +65,7 @@ def TestFromIterable():
([],
())
]
for
args
,
want
in
cases
:
got
=
tuple
(
itertools
.
from_iterable
(
args
))
got
=
tuple
(
itertools
.
chain
.
from_iterable
(
args
))
assert
got
==
want
,
'tuple(from_iterable%s) == %s, want %s'
%
(
args
,
got
,
want
)
def
TestIFilter
():
...
...
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