
peek () except StopIteration : return False return True def peek ( self, default = _marker ): """Return the item that will be next returned from ``next()``. _cache = deque () def _iter_ ( self ): return self def _bool_ ( self ): try : self.

list(p) """ def _init_ ( self, iterable ): self. list(p) > if not p: # peekable is exhausted. To check whether a peekable is exhausted, check its truth value: > p = peekable() > if p: # peekable has items. > p = peekable() > p 'a' > p 'b' > next(p) 'a' Negative indexes are supported, but be aware that they will cache the remaining items in the source iterator, which may require significant storage. Index 0 is the item that will be returned by :func:`next`, index 1 is the item after that, and so on: The values up to the given index will be cached. > p = peekable() > p.peek('hi') 'hi' peekables also offer a :meth:`prepend` method, which "inserts" items at the head of the iterable: > p = peekable() > p.prepend(10, 11, 12) > next(p) 10 > p.peek() 11 > list(p) peekables can be indexed. This won't advance the iterator: > p = peekable() > p.peek() 'a' > next(p) 'a' Pass :meth:`peek` a default value to return that instead of raising ``StopIteration`` when the iterator is exhausted. Call :meth:`peek` on the result to get the value that will be returned by :func:`next`.

class peekable : """Wrap an iterator to allow lookahead and prepending elements. recipes import ( _marker, _zip_equal, UnequalIterablesError, consume, flatten, pairwise, powerset, take, unique_everseen, ) _all_ =

Import warnings from collections import Counter, defaultdict, deque, abc from collections.abc import Sequence from concurrent.futures import ThreadPoolExecutor from functools import partial, reduce, wraps from heapq import merge, heapify, heapreplace, heappop from itertools import ( chain, compress, count, cycle, dropwhile, groupby, islice, repeat, starmap, takewhile, tee, zip_longest, ) from math import exp, factorial, floor, log from queue import Empty, Queue from random import random, randrange, uniform from operator import itemgetter, mul, sub, gt, lt, ge, le from sys import hexversion, maxsize from time import monotonic from.
