Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'subject:Python': 0.05; 'subject:two': 0.07; 'garbage': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'through.': 0.09; 'to)': 0.09; 'resulting': 0.13; '"in"': 0.16; 'afterwards.': 0.16; 'example?': 0.16; 'iterated': 0.16; 'subject:2.7.3': 0.16; 'subject:between': 0.16; 'subject:these': 0.16; 'variable.': 0.16; 'wrote:': 0.17; 'url:view': 0.18; 'subject:] ': 0.19; 'question.': 0.20; 'received:emailsrvr.com': 0.22; 'second': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'run': 0.28; 'gary': 0.29; 'once,': 0.29; 'once.': 0.29; 'case,': 0.29; 'received:(smtp server)': 0.30; 'accessible': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'list': 0.35; 'pm,': 0.35; 'but': 0.36; 'url:org': 0.36; 'does': 0.37; 'to:addr:python.org': 0.39; 'called': 0.39; 'your': 0.60; 'first': 0.61; 'here': 0.65; 'tricky': 0.91 X-Virus-Scanned: OK Date: Sun, 17 Mar 2013 18:18:12 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> In-Reply-To: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363570008 news.xs4all.nl 6909 [2001:888:2000:d::a6]:57471 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41379 On 03/17/2013 05:58 PM, Yves S. Garret wrote: > N00b question. But here is the code: > > http://bin.cakephp.org/view/709201806 > > In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what > happens in the second example? Does the loop after "in" get run only once or multiple number of times? Just once. The sorted fn is called just once, and the resulting list is iterated through. In your first case, the list is bound to (assigned to) a name so it is accessible afterwards. In the second case, it is available for garbage collection immediately after the loop finishes. Gary Herron