ETA: See raymondh's post below.
ETA: See raymondh's post below.
* The with-statement only causes the file to be closed after use. It has nothing to do with iteration.
* Files themselves are self-iterable (anything that loops over a file object uses a line-at-a-time iterator). Even writing "for line in f: ..." causes you to loop a line at a time without the whole file being in memory all at once.
* Sets are just one of many objects that takes an iterable as an argument: min(f), max(f), list(f), tuple(f), etc.
I'm not sure I understand your third comment though. As I understand it, iterables have an __iter__ method. __iter__ methods return iterators. So an iterator for the iterable f traverses f and sends f's values to, in this case, set(). I believe we agree there. My initial concern was simply that the statement could be read "The iterator, set(), uses f.", and I don't see where the disagreement arises.