classification
Title: docs: summary page - generator vs iterator vs iterable
Type: enhancement Stage:
Components: Documentation Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ezio.melotti, techtonik, terry.reedy
Priority: normal Keywords:

Created on 2013-05-01 06:34 by techtonik, last changed 2013-05-04 17:19 by ezio.melotti.

Messages (3)
msg188203 - (view) Author: anatoly techtonik (techtonik) Date: 2013-05-01 06:34
Docs lack a good summary page comparing three concepts. The main question is how do I tell if something is a sequence, generator, iterator or iterable? I found myself puzzled that range() is neither generator or iterator.
msg188334 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-05-03 23:42
Briefly,
An iterable is an object that can be iterated with an iterator.
An iterator is an iterable that responds to next() calls, including the implicit calls in a for statement.
A generator is an iterator created by a generator function, which is a function with a yield keyword in its body.
A sequence is an iterable with minimal sequence methods.

The four terms are all in the glossary. The entry for iterable already points to the other three. What do you think is missing?

A range (as documented) is an immutable sequence.
msg188336 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-05-03 23:51
To make the subset relationships clear in the iterable entry, perhaps replace
  See also iterator, sequence, and generator. 
with
  Some iterables are iterators and some iterators are generators. Some iterables are sequences. For details, see iterator, sequence, and generator.

I see that 'generator' is currently used in the 3.3.1 glossary for 'generator function' and there is no entry for generator (object) proper. I thought that had been fixed after pydev discussion.
History
Date User Action Args
2013-05-04 17:19:48ezio.melottisetnosy: + ezio.melotti

type: enhancement
versions: + Python 2.7, Python 3.3, Python 3.4
2013-05-03 23:51:43terry.reedysetmessages: + msg188336
2013-05-03 23:42:01terry.reedysetnosy: + terry.reedy
messages: + msg188334
2013-05-01 06:34:47techtonikcreate