fork download
  1. # https://stackoverflow.com/questions/73582708/does-re-finditer-store-the-values-it-finds-in-the-memory
  2.  
  3. def stupid_iterator(seq):
  4. """Make an iterator for seq"""
  5. def _iter():
  6. return seq.pop(0)
  7. return _iter
  8.  
  9. i = stupid_iterator([1, 2, 3])
  10. print(i) # for fun
  11. print(i())
  12. print(i())
  13. print(i())
  14. print(i())
  15.  
Runtime error #stdin #stdout #stderr 0.15s 23460KB
stdin
Standard input is empty
stdout
<function stupid_iterator.<locals>._iter at 0x1513b07a3ea0>
1
2
3
stderr
Traceback (most recent call last):
  File "./prog.py", line 14, in <module>
  File "./prog.py", line 6, in _iter
IndexError: pop from empty list