obtaining multiple values from a function.

Paul Rudin paul.nospam at rudin.co.uk
Tue Sep 25 05:41:58 EDT 2007


Ben Finney <bignose+hates-spam at benfinney.id.au> 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 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 candidate would be to give the whole
sequence of partial reductions. I'm not sure if this would be
generally useful, but it would give a succinct way to do the Fibonacci
sequence:

itertools.ireduce(operator.add, itertools.count())




More information about the Python-list mailing list