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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 24 10:46:18 CET 2006


Brett Cannon wrote:

 > Someone else wrote:

> > When I was just
> > first learning Python I thought this would work:
> >
> >   for item in select_results:
> >       ...
> >   else:
> >       ... stuff when there are no items ...
> >
> > But it doesn't work like that.

I have to agree that's actually a more intuitive use
of "else" in relation to a for-loop. It's a pity that
some other word wasn't chosen that would have left
"else" free for this purpose.

Could something perhaps be done about this in Py3k?
Blatantly changing the meaning of "else" here might
be going too far, but maybe some other construct could
be found that expresses the same intent.

Greg


More information about the Python-3000 mailing list