Re: [Python-ideas] 'default' keyword argument for max(), min()

On Thu, Apr 16, 2009 at 10:08 PM, Raymond Hettinger <python@rcn.com> wrote:
Are you looking specifically for examples with non-sequence iterables ? As I mentioned, I would prefer "min(s, default=0)" from "min(s) if s else 0" if the former was available as it's more future-proof.
Indeed, all() looks better in this case; maybe I was using the min value later and did it this way. I'll search for any actual examples as I recalled this from memory.
That's a valid point, although the main mental burden lies in the multi-arg vs iterable single-arg peculiarity; optional keyword arguments scale better in general. As another aside, I'm curious of the relative frequency between the single-arg vs the multi-arg form. I personally use the former much more than multi-args, and for those it's almost always two args and very rarely three or more. Given that min(x,y) can be now written as an equivalent if/else expression, I'm wondering if the min/max signature would be the way it is if it was proposed now for the first time.
Interesting, it took me a few seconds to think of why you might read it otherwise since it's "obvious" to me what it means. I had never thought of the initial value semantics wrt to min/max before this thread came up.
Yes, that's neat, and default() may be a good candidate for addition to itertools.
I sense that you're going to try to force this through but wish
No, not at all. I'm not the OP and as I said, I have accepted that I should think of min/max more like division than a missing key/attribute. One can't just blindly use "min(x)" without considering the case where x is empty as he can't use 1/x without considering the case where x is zero. It's slightly inconvenient if all you have is a bunch of non-negative numbers and the "obvious" default is zero but generally explicit is better than implicit. George
participants (1)
-
George Sakkis