[Python-3000] Builtin iterator type

George Sakkis gsakkis at rutgers.edu
Wed Nov 15 16:39:26 CET 2006


On 11/15/06, Nick Coghlan <ncoghlan at gmail.com> wrote:

> As far as the 'flexible iterator' idea goes, I've had a rough implementation
> of such a beast sitting on my hard drive for the last year and a half (since
> shortly after that January '05 thread I linked to earlier in this discussion).
> My conclusion from writing it was that depending on the implementation choices
> you make in developing the class you will end up in one of two situations:
>
> either 1. The entire iterator is soon loaded into memory as you manipulate it
>
> or 2. The underlying iterator is consumed unexpectedly as you manipulate it

For (2), I'd say it depends on your expectations. If you expect x[:5]
to have always the same semantics you expect from a list, then yes,
you will be surprized if x is an iterator, as you may be surprized if
x is a numpy array. However, it seems contradictory for Python to
insist on specific method semantics, while at the same time is
reluctant to enforce APIs for omnipresent interfaces like sequences
and iterators.

George


More information about the Python-3000 mailing list