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
to say

   for x from iterator:

This would force people to keep the distinction firmly
in mind and might lead to less confusion.

Greg
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to