kopia lustrzana https://github.com/micropython/micropython-lib
itertools: Make islice() work with arbitrary iterables, not just sequences.
rodzic
9a81d0ec25
commit
7bbdc050d3
|
@ -34,11 +34,17 @@ def islice(p, start, stop=(), step=1):
|
||||||
if stop == ():
|
if stop == ():
|
||||||
stop = start
|
stop = start
|
||||||
start = 0
|
start = 0
|
||||||
|
# TODO: optimizing or breaking semantics?
|
||||||
|
if start >= stop:
|
||||||
|
return
|
||||||
|
it = iter(p)
|
||||||
|
for i in range(start):
|
||||||
|
next(it)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
yield next(it)
|
||||||
yield p[start]
|
for i in range(step - 1):
|
||||||
except IndexError:
|
next(it)
|
||||||
return
|
|
||||||
start += step
|
start += step
|
||||||
if start >= stop:
|
if start >= stop:
|
||||||
return
|
return
|
||||||
|
|
Ładowanie…
Reference in New Issue