[Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence
Nick Coghlan
ncoghlan at gmail.com
Thu Oct 14 01:14:55 CEST 2010
On Thu, Oct 14, 2010 at 7:54 AM, Tal Einat <taleinat at gmail.com> wrote:
> class RunningMax(RunningCalc):
> def __init__(self):
> self.max_value = None
>
> def feed(self, value):
> if self.max_value is None or value > self.max_value:
> self.max_value = value
>
> def feedMultiple(self, values):
> self.feed(max(values))
>
> feedMultiple() would have a naive default implementation in the base class.
>
> Now this is non-trivial and can certainly be useful. Thoughts? Comments?
Why use feed() rather than the existing generator send() API?
def runningmax(default_max=None):
max_value = default_max
while 1:
value = max(yield max_value)
if max_value is None or value > max_value:
max_value = value
That said, I think this kind of thing requires too many additional
assumptions about how things are driven to make a particularly good
candidate for standard library inclusion without use in PyPI library
first.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list