[Python-3000] Iterators for dict keys, values, and items == annoying :)
greg.ewing at canterbury.ac.nz
Fri Mar 24 10:44:54 CET 2006
Ian Bicking wrote:
> Iterators look a lot like containers.
Actually, they hardly look like containers at all. About
the only thing you can do with a container that you can
also do with an iterator is use it in a for-loop. There
are a great many other things you *can't* do with an
iterator -- index it, slice it, take its len(), etc.
In some ways it's rather misleading that you're
allowed to say
for x in iterator:
because the items are not "in" the iterator, they're
*produced* by the iterator on demand.
I've speculated that perhaps it should be illegal to
use an iterator that way, and you would instead have
for x from iterator:
This would force people to keep the distinction firmly
in mind and might lead to less confusion.
More information about the Python-3000