def eat(iterator, amount): """Advance an iterator n-steps ahead. If n is None, eat entirely. Taken from the Python documentation. Under the PSF license. :param iterator: An iterator. :param amount: The number of steps to advance. :yields: An iterator. """ # Use functions that consume iterators at C speed. if amount is None: # Feed the entire iterator into a zero-length deque. collections.deque(iterator) else: # Advance to the empty slice starting at position n. builtins.next(itertools.islice(iterator, amount, amount), None)
def nth(iterable, index, default=None): """Returns the nth element out of an iterable. :param iterable: Iterable sequence. :param index: Index :param default: If not found, this or ``None`` will be returned. :returns: nth element of the iterable sequence. """ return builtins.next(itertools.islice(iterable, index, None), default)
def walker(path, topdown=topdown, followlinks=followlinks): """Alternative walker.""" yield builtins.next(os.walk(path, topdown=topdown, followlinks=followlinks))
def walker(path, topdown=topdown, followlinks=followlinks): """Alternative walker.""" yield builtins.next( os.walk(path, topdown=topdown, followlinks=followlinks))