[Python-ideas] [Python-Dev] minmax() function returning (minimum, maximum) tuple of a sequence (original) (raw)

Ron Adam rrr at ronadam.com
Fri Oct 15 22:00:53 CEST 2010


On 10/15/2010 02:04 PM, Arnaud Delobelle wrote:

Because it would always interpret a list of values as a single item.

This function looks at args and if its a single value without an "iter" method, it passes it to min as min([value], **kwds) instead of min(value, **kwds). But there are many iterable objects which are also comparable (hence it makes sense to consider their min/max), for example strings. So we get: xmin("foo", "bar", "baz") == "bar" xmin("foo", "bar") == "bar" but: xmin("foo") == "f" This will create havoc in your running min routine. (Notice the same will hold for min() but at least you know that min(x) considers x as an iterable and complains if it isn't)

Yes

There doesn't seem to be a way to generalize min/max in a way to handle all the cases without knowing the context.

So in a coroutine version of Tals class, you would need to pass a hint along with the value.

Ron



More information about the Python-ideas mailing list