itertools: cycle(): Factor out common code.

pull/43/head
Paul Sokolovsky 2015-08-25 21:27:54 +03:00
rodzic 9c6a8dbd4b
commit 91563f06db
1 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -6,8 +6,6 @@ def count(start=0, step=1):
def cycle(p):
try:
len(p)
while p:
yield from p
except TypeError:
# len() is not defined for this type. Assume it is
# a finite iterable so we must cache the elements.
@ -15,8 +13,10 @@ def cycle(p):
for i in p:
yield i
cache.append(i)
while cache:
yield from cache
p = cache
while p:
yield from p
def repeat(el, n=None):
if n is None: