A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

Chris Angelico rosuav at gmail.com
Tue Feb 28 18:24:18 EST 2012

On Wed, Feb 29, 2012 at 9:56 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> On Feb 24, 8:54 am, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
>> In Python 4000, I think for loops should be spelled:
>> for name in iterable:
>>     # for block
>> then:
>>     # only if not exited with break
>> else:
>>     # only if iterable is empty
>> and likewise for while loops.
> I like this syntax better than the current syntax, however, it is
> STILL far too confusing!

Absolutely, it's FAR too confusing. Every syntactic structure should
have the addition of a "foo:" suite, which will run when the
programmer expects it to and no other time. This would solve a LOT of


More information about the Python-list mailing list