[Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence (original) (raw)
Tal Einat taleinat at gmail.com
Fri Oct 15 05:05:43 CEST 2010
- Previous message: [Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence
- Next message: [Python-ideas] minmax() function returning (minimum, maximum) tuple of a sequence
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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(defaultmax=None): maxvalue = defaultmax while 1: value = max(yield maxvalue) if maxvalue is None or value> maxvalue: maxvalue = 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
- Previous message: [Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence
- Next message: [Python-ideas] minmax() function returning (minimum, maximum) tuple of a sequence
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]