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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 24 11:03:58 CET 2006


Ian Bicking wrote:

> If you could somehow count how many times 
> the loop had run, that'd work great; but I don't see any way to do that 
> without new syntax.

   line = None
   for line in some_lines:
     ...
   if line is None:
     # we didn't get any lines

Speculating on a syntax to make this one line shorter:

   for line in some_lines else None:
     ...
   if line is None:
     # we didn't get any lines

Or using a different keyword:

   for line in some_lines:
     ...
   except:
     # we didn't get any lines

Greg


More information about the Python-3000 mailing list