Iterators in Python

1. for "x in y" loops

 for X in Y  loops are actually:

itr = iter(Y) # Which, if you look deeply is: itr = Y.__iter__

try:
  while (True):
    val = itr.next()
    do_something_with(val)
except StopIteration:
  pass

return

2. Reference

  1. Charming Python: Iterators and simple generators

Python/Iterators (last edited 2010-09-11 20:38:48 by SandipBhattacharya)