kopia lustrzana https://github.com/micropython/micropython-lib
itertools: Add partial implementation.
rodzic
312377620b
commit
50f37fe01a
|
@ -0,0 +1,36 @@
|
||||||
|
def count(start, step=1):
|
||||||
|
while True:
|
||||||
|
yield start
|
||||||
|
start += step
|
||||||
|
|
||||||
|
def cycle(p):
|
||||||
|
while True:
|
||||||
|
yield from p
|
||||||
|
|
||||||
|
def repeat(el, n=None):
|
||||||
|
if n is None:
|
||||||
|
while True:
|
||||||
|
yield el
|
||||||
|
else:
|
||||||
|
for i in range(n):
|
||||||
|
yield el
|
||||||
|
|
||||||
|
def chain(*p):
|
||||||
|
for i in p:
|
||||||
|
yield from i
|
||||||
|
|
||||||
|
def islice(p, start, stop=(), step=1):
|
||||||
|
if stop == ():
|
||||||
|
stop = start
|
||||||
|
start = 0
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
yield p[start]
|
||||||
|
except IndexError:
|
||||||
|
return
|
||||||
|
start += step
|
||||||
|
if start >= stop:
|
||||||
|
return
|
||||||
|
|
||||||
|
def tee(iterable, n=2):
|
||||||
|
return [iter(iterable)] * n
|
Ładowanie…
Reference in New Issue