Re: obtaining multiple values from a function.

2007-09-25 Thread Paul Rudin
Carsten Haese <[EMAIL PROTECTED]> writes: > ... > That's not the Fibonacci sequence. Bah, you're right of course, I should be more more careful before posting these things. -- http://mail.python.org/mailman/listinfo/python-list

Re: obtaining multiple values from a function.

2007-09-25 Thread Carsten Haese
On Tue, 2007-09-25 at 10:41 +0100, Paul Rudin wrote: > Going off on a tangent a bit, but I was idly considering the absence > of itertools.ireduce the other day. A problem is that reduce gives a > single result, so it's not clear what ireduce would do (perhaps why > it's not there). One obvious can

Re: obtaining multiple values from a function.

2007-09-25 Thread Paul Rudin
Ben Finney <[EMAIL PROTECTED]> writes: > > If, instead, it makes sense for the results to be iterated over, you > can write a function that yields results one at a time, without > necessarily knowing in advance what the entire set will be:: > > >>> def fib(max_result): Going off on a tangent

Re: obtaining multiple values from a function.

2007-09-25 Thread Ben Finney
Shriphani <[EMAIL PROTECTED]> writes: > If I have a function that loops over a few elements and is expected to > throw out a few tuples as the output, then what should I be using in > place of return ? If it makes sense for the set of results to be returned all at once, then return the object tha

Re: obtaining multiple values from a function.

2007-09-25 Thread Peter Otten
Shriphani wrote: > If I have a function that loops over a few elements and is expected to > throw out a few tuples as the output, then what should I be using in > place of return ? Use a generator and have it /yield/ rather than /return/ results: >>> def f(items): ... for item in items: ...