Skip to content

Commit 50f37fe

Browse files
committed
itertools: Add partial implementation.
1 parent 3123776 commit 50f37fe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

itertools/itertools.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def count(start, step=1):
2+
while True:
3+
yield start
4+
start += step
5+
6+
def cycle(p):
7+
while True:
8+
yield from p
9+
10+
def repeat(el, n=None):
11+
if n is None:
12+
while True:
13+
yield el
14+
else:
15+
for i in range(n):
16+
yield el
17+
18+
def chain(*p):
19+
for i in p:
20+
yield from i
21+
22+
def islice(p, start, stop=(), step=1):
23+
if stop == ():
24+
stop = start
25+
start = 0
26+
while True:
27+
try:
28+
yield p[start]
29+
except IndexError:
30+
return
31+
start += step
32+
if start >= stop:
33+
return
34+
35+
def tee(iterable, n=2):
36+
return [iter(iterable)] * n

0 commit comments

Comments
 (0)