From: joe at strout.net (Joe Strout)
Date: Fri, 23 Apr 1999 11:11:46 -0700
Subject: Style/efficiency question using 'in'
References: <3720B3B9.98BED320@earth.ox.ac.uk>
Message-ID: <joe-230419991111467745@chinacat.salk.edu>
X-UID: 1321                                                  

In article <3720B3B9.98BED320 at earth.ox.ac.uk>, Nick Belshaw
<nickb at earth.ox.ac.uk> wrote:

> If I do something like :-
> 
> ------------------
> def  func1():
>     return 1,2,3,4,5,6,7,8
> 
> for x in func1():
>     print x
> ------------------
> 
> it works as expected but is the use of a function in a loop undesirable?
> Is the function called once to build the loop or is it called each loop
> increment and therefore undesirable if there is much overhead?

It's called once to build the loop, as you can prove to yourself by
inserting "print 'spam'" into func1().

Cheers,
-- Joe

-- 
,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe at strout.net             http://www.strout.net              |
`------------------------------------------------------------------'
Check out the Mac Web Directory!    http://www.strout.net/macweb.cgi




