kopia lustrzana https://github.com/micropython/micropython-lib
itertools: cycle(): Factor out common code.
rodzic
9c6a8dbd4b
commit
91563f06db
|
@ -6,8 +6,6 @@ def count(start=0, step=1):
|
||||||
def cycle(p):
|
def cycle(p):
|
||||||
try:
|
try:
|
||||||
len(p)
|
len(p)
|
||||||
while p:
|
|
||||||
yield from p
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# len() is not defined for this type. Assume it is
|
# len() is not defined for this type. Assume it is
|
||||||
# a finite iterable so we must cache the elements.
|
# a finite iterable so we must cache the elements.
|
||||||
|
@ -15,8 +13,10 @@ def cycle(p):
|
||||||
for i in p:
|
for i in p:
|
||||||
yield i
|
yield i
|
||||||
cache.append(i)
|
cache.append(i)
|
||||||
while cache:
|
p = cache
|
||||||
yield from cache
|
while p:
|
||||||
|
yield from p
|
||||||
|
|
||||||
|
|
||||||
def repeat(el, n=None):
|
def repeat(el, n=None):
|
||||||
if n is None:
|
if n is None:
|
||||||
|
|
Ładowanie…
Reference in New Issue