[Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence
Tal Einat
taleinat at gmail.com
Fri Oct 15 05:05:43 CEST 2010
On Fri, Oct 15, 2010 at 4:09 AM, Ron Adam wrote:
>
>
> On 10/13/2010 07:13 PM, Tal Einat wrote:
>>
>> On Thu, Oct 14, 2010 at 1:14 AM, Nick Coghlan wrote:
>>>
>>> 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
>>
>> I tried using generators for this and it came out very clumsy. For one
>> thing, using generators for this requires first calling next() once to
>> run the generator up to the first yield, which makes the user-facing
>> API very confusing. Generators also have to yield a value at every
>> iteration, which is unnecessary here. Finally, the feedMultiple
>> optimization is impossible with a generator-based implementation.
>
> Something I noticed about the min and max functions is that they treat
> values and iterable slightly different.
Sorry, my bad. The max in "value = max(yield max_value)" was an error,
it should have been removed.
As Guido mentioned, there is never a reason to do max(value) where
value is not an iterable.
- Tal
More information about the Python-ideas
mailing list