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): 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: