MCPcopy
hub / github.com/more-itertools/more-itertools / peek

Method peek

more_itertools/more.py:391–405  ·  view source on GitHub ↗

Return the item that will be next returned from ``next()``. Return ``default`` if there are no items left. If ``default`` is not provided, raise ``StopIteration``.

(self, default=_marker)

Source from the content-addressed store, hash-verified

389 return True
390
391 def peek(self, default=_marker):
392 """Return the item that will be next returned from ``next()``.
393
394 Return ``default`` if there are no items left. If ``default`` is not
395 provided, raise ``StopIteration``.
396
397 """
398 if not self._cache:
399 try:
400 self._cache.append(next(self._it))
401 except StopIteration:
402 if default is _marker:
403 raise
404 return default
405 return self._cache[0]
406
407 def prepend(self, *items):
408 """Stack up items to be the next ones returned from ``next()`` or

Callers 6

__bool__Method · 0.95
test_peek_defaultMethod · 0.45
test_simple_peekingMethod · 0.45
test_slicing_errorMethod · 0.45
test_lazy_consumptionMethod · 0.45

Calls

no outgoing calls

Tested by 5

test_peek_defaultMethod · 0.36
test_simple_peekingMethod · 0.36
test_slicing_errorMethod · 0.36
test_lazy_consumptionMethod · 0.36