[Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence
Masklinn
masklinn at masklinn.net
Mon Oct 11 07:50:14 CEST 2010
On 2010-10-11, at 02:55 , Zac Burns wrote:
>
> Unfortunately this solution seems incompatable with the implementations with
> for loops in min and max (EG: How do you switch functions at the right
> time?) So it might take some tweaking.
As far as I know, there is no way to force lockstep iteration of arbitrary functions in Python. Though an argument could be made for adding coroutine capabilities to builtins and library functions taking iterables, I don't think that's on the books.
As a result, this function would devolve into something along the lines of
def apply(iterable, *funcs):
return map(lambda c: c[0](c[1]), zip(funcs, tee(iterable, len(funcs))))
which would run out of memory on very long or nigh-infinite iterables due to tee memoizing all the content of the iterator.
More information about the Python-ideas
mailing list