Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:when': 0.07; 'executes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'return,': 0.09; 'non-empty': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'typo': 0.16; 'yup,': 0.16; 'examples': 0.16; 'wrote:': 0.18; '(or': 0.22; 'from:addr:web.de': 0.23; 'code': 0.26; 'there.': 0.27; 'not.': 0.28; 'regardless': 0.31; 'break': 0.32; 'header:X-Complaints-To:1': 0.34; 'loop': 0.34; 'steven': 0.34; 'subject:/': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'but': 0.37; 'to:addr:python.org': 0.40; 'your': 0.61; 'break.': 0.84; 'show,': 0.84; 'confusion.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty Date: Fri, 24 Feb 2012 16:16:42 +0100 Organization: None References: <14ba4b39-4066-4d24-89d7-3c7c85aab85c@b18g2000vbz.googlegroups.com> <51a08251-1e6e-45f3-8531-b53e87b7db8b@r1g2000yqk.googlegroups.com> <4f47a49e$0$29989$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849ddf.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330096575 news.xs4all.nl 6975 [2001:888:2000:d::a6]:37846 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20817 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.