Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41383

Re: [Python 2.7.3] What's the difference between these two uses of "for"?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <yoursurrogategod@gmail.com>
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; 'through.': 0.09; 'to)': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '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; 'thanks.': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; '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; 'accessible': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'does': 0.37; 'received:209': 0.37; 'called': 0.39; 'your': 0.60; 'first': 0.61; 'here': 0.65; '2013': 0.84; 'tricky': 0.91
X-Received by 10.49.75.66 with SMTP id a2mr1126313qew.21.1363571993233; Sun, 17 Mar 2013 18:59:53 -0700 (PDT)
Newsgroups comp.lang.python
Date Sun, 17 Mar 2013 18:59:53 -0700 (PDT)
In-Reply-To <mailman.3403.1363570008.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=70.188.179.16; posting-account=AvekzAoAAABj-TclKcOWQmXwA49MFPGX
References <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> <mailman.3403.1363570008.2939.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 70.188.179.16
MIME-Version 1.0
Subject Re: [Python 2.7.3] What's the difference between these two uses of "for"?
From "Yves S. Garret" <yoursurrogategod@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.3404.1363571995.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363571995 news.xs4all.nl 6949 [2001:888:2000:d::a6]:36583
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41383

Show key headers only | View raw


On Sunday, March 17, 2013 9:18:12 PM UTC-4, Gary Herron wrote:
> 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

Gotcha, thanks.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 17:58 -0700
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-17 20:24 -0500
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Gary Herron <gary.herron@islandtraining.com> - 2013-03-17 18:18 -0700
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 18:59 -0700
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 18:59 -0700
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:14 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Dave Angel <davea@davea.name> - 2013-03-18 07:38 -0400
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:14 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:33 -0400
          Re: What's the difference between these two uses of "for"? alex23 <wuwei23@gmail.com> - 2013-03-18 18:08 -0700
        Re: [Python 2.7.3] What's the difference between these two uses of "for"? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-18 02:44 +0000
          Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:51 -0400
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 21:28 -0400
    Re: [Python 2.7.3] What's the difference between these two uses of "for"? "Yves S. Garret" <yoursurrogategod@gmail.com> - 2013-03-17 19:01 -0700
      Re: [Python 2.7.3] What's the difference between these two uses of "for"? Roy Smith <roy@panix.com> - 2013-03-17 22:28 -0400
  Re: [Python 2.7.3] What's the difference between these two uses of "for"? Terry Reedy <tjreedy@udel.edu> - 2013-03-18 00:37 -0400

csiph-web