A quirk/gotcha of for i, x in enumerate(seq) when seq is empty
__peter__ at web.de
Fri Feb 24 10:16:42 EST 2012
Steven D'Aprano wrote:
>> The code in the else suite executes only when the for loop is left via
>> break. A non-empty iterable is required but not sufficient.
> You have a typo there. As your examples show, the code in the else suite
> executes only when the for loop is NOT left via break (or return, or an
> exception). The else suite executes regardless of whether the iterable is
> empty or not.
Yup, sorry for the confusion.
More information about the Python-list