[Python-3000] Iterators for dict keys, values, and items == annoying :)

Guido van Rossum guido at python.org
Fri Mar 24 16:26:39 CET 2006


On 3/24/06, Barry Warsaw <barry at python.org> wrote:
> On Thu, 2006-03-23 at 17:06 -0800, Guido van Rossum wrote:
>
> > The pattern with the 'empty' flag is only needed when due to API
> > constraints you have only got an iterator.
>
> Which can happen quite often actually.  Perhaps making the original
> object available as an attribute of the iterator can help in those
> situations though.

It can't work, at least not in general. How do you do this if the
iterator is a generator? Or an infinite sequence? Or a filter? It
can't be made part of the iterator protocol. You can design your own
extension of the iterator protocol, but then it wouldn't accept
arbitrary iterators any more.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list