"""Authored finite iterator observation, no external input."""
import itertools,json,platform
def demo():
 visits=[]
 def factory():
  for x in [11,22,33]:visits.append(x);yield x
 g=factory();same=iter(g) is g;first=list(g);after_first=len(visits);second=list(g);after_second=len(visits);stops=[]
 for _ in range(2):
  try:next(g)
  except StopIteration:stops.append(True)
 assert first==[11,22,33] and second==[] and stops==[True,True] and visits==first
 saved=list(factory());repeated=[list(saved),list(saved)];fresh=[list(factory()),list(factory())]
 assert repeated==fresh==[[11,22,33],[11,22,33]]
 h=factory();peek=next(h);remaining=list(h);assert peek==11 and remaining==[22,33]
 j=factory();head=next(j);restored=list(itertools.chain([head],j));assert restored==first
 empty=iter([]);assert list(empty)==[]
 return {'runtime':platform.python_version(),'iter_generator_is_self':same,'first':first,'second':second,'produced_count_after_first_and_second':[after_first,after_second],'repeated_stop_iteration':stops,'materialized_two_passes':repeated,'factory_two_passes':fresh,'peek_consumes':{'head':peek,'remaining':remaining,'explicit_chain_restore':restored},'scope':'Three finite authored values; materialization bounded here, not restartable external stream/checkpoint.'}
if __name__=='__main__':print(json.dumps(demo(),ensure_ascii=True,indent=2))
