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 == ():
|
||||
stop = start
|
||||
start = 0
|
||||
while True:
|
||||
try:
|
||||
yield p[start]
|
||||
except IndexError:
|
||||
# TODO: optimizing or breaking semantics?
|
||||
if start >= stop:
|
||||
return
|
||||
it = iter(p)
|
||||
for i in range(start):
|
||||
next(it)
|
||||
|
||||
while True:
|
||||
yield next(it)
|
||||
for i in range(step - 1):
|
||||
next(it)
|
||||
start += step
|
||||
if start >= stop:
|
||||
return
|
||||
|
|
Ładowanie…
Reference in New Issue