PEP 255: Simple Generators

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Jun 21 01:21:13 EDT 2001


Just van Rossum wrote:
> 
> The next two functions are more or less equivalent:
> 
> def returnThreeValues():
>         return 1, 2, 3
> 
> def generateThreeValues():
>         yield 1
>         yield 2
>         yield 3

I would agree with you if you had said they are
equivalent *in the following context*:

  for i in returnThreeValues():
    ...

  for i in generateThreeValues():
    ...

But you have to fuzz up your thinking somewhat in order
to see them as equivalent *in general*, and I can't
see fuzzy thinking as anything but a liability when
programming.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list