4 ms·
That wouldn't make any sense. >>> min(['a', 'b']) 'a' >>> min(['a']) 'a' >>> min([]) float('-inf') # ??? An empty list is not a list of numbers.
by oefrha 7y ago
That wouldn't make any sense.
>>> min(['a', 'b'])
'a'
>>> min(['a'])
'a'
>>> min([])
float('-inf') # ???
An empty list is not a list of numbers. It's not a list of anything.
(You can use typing hinting to indicate the type of an empty list, but type hints are ignored by the interpreter.)
- enriquto 7y agoI'd rather argue that "min" only makes sense for numbers and not for other objects.
- oefrha 7y agoNo, min makes sense for any set with a total order. Sometimes partial order too.
- enriquto 7y agoTypically you would use "least" and "greatest" (for a partial order) or "first" and "last" (for a total order). It sounds very strange to talk about "min" and "max" for strings, for example. Do you call the first word on a dictionary the minimal word? But then again, what can you expect from a language that uses "+", the quintessential notation for commutative operations, for the (very non-commutative) operation of concatenation? Doubly sad when you realize that the language was designed by an actual mathematician.
- oefrha 7y agoI was trained as a mathematician and I can confirm that min and max (for minimal and maximal, or minimum and maximum) are mathematically accurate terms. See https://en.wikipedia.org/wiki/Maximal_and_minimal_elements https://en.wikipedia.org/wiki/Maximal_and_minimal_elements
- enriquto 7y ago> I can confirm that min and max (for minimal and maximal, or minimum and maximum) are mathematically accurate terms. This is true, but they do not have exactly the same meaning. On a poset you do not speak of "the min", but of "a min". You still have "the least", which is a different notion.
- oefrha 7y agoWhich is why I said "min makes sense for any set with a total order. Sometimes partial order too." There's no ambiguity for total order whatsoever.
- bakery2k 7y ago> what can you expect from a language that uses "+", the quintessential notation for commutative operations, for the (very non-commutative) operation of concatenation? Is this any worse than using `+` for floating-point addition, which isn't even associative?
- enriquto 7y agoBut floating point addition is commutative! Even if it wasn't, floating point numbers are very often regarded as approximations of real numbers, where addition is associative. String concatenation cannot be construed to have any resemblance of commutativity.
- quietbritishjim 7y ago> Typically you would use "least" and "greatest" (for a partial order) or "first" and "last" (for a total order). This is just absolutely not true. It is certainly "min" and "max" for any total order, they definitely don't have to be numbers or even numbers with the usual ordering (as confusing as that would be with a set of numbers but the reverse ordering). "first" and "last"? I've never heard that. I haven't worked with partial orders so much that I can be as confident about that, perhaps "least" and "greatest" are the correct terms. But "min" and "max" are certainly used sometimes by non-specialists (i.e. professional mathmaticians that don't necessarily spend a lot of time with posets) without any confusion.
- throwaway_pdp09 7y agoIntegers have an (intrinsic & natural) total order. Do characters? I'd say no. We represent them as integers, then expose those underlying integers because it's extremely useful for efficiency purposes, but I'd pretty strongly argue that that's an optimisation only and not an intrinsic to the alphabet. 'a' < 'b' only by accident of history. It could just as easily have been the reverse.
- falcor84 7y ago"betaalph" doesn't quite have that ring to it
- falcor84 7y agoAlso, it's worth noting that in Judaism and some other religions these things have religious significance stretched to them. In this particular example, Aleph is considered to equal 1 and Bet is considered to equal 2. https://en.wikipedia.org/wiki/Gematria https://en.wikipedia.org/wiki/Gematria
- eru 7y agoTo give some more examples: Tuples have a reasonable natural total order: just compare component wise. And minimum of a list of tuples makes sense. You could argue that alphabetic ordering is artificial, but it's hard to argue that it ain't well established and non-surprising. Interestingly, not all numbers have intuitive orders. Eg complex numbers don't really have a good preferred ordering. And the ordering of p-adic numbers is well defined and unique, but really weird.
- throwaway_pdp09 7y ago> Tuples have a reasonable natural total order No they don't. (1, 2) > (2, 1) = ??? To compare tuples you need a generalisation of comparison which includes 'incomparable' as an outcome. See lattices https://en.wikipedia.org/wiki/Lattice_%28order%29 https://en.wikipedia.org/wiki/Lattice_%28order%29 > but it's hard to argue that [alphabetic ordering] ain't well established it is, agreed... > and non-surprising ...agreed again, only because it's a convention you know so well (had it been reversed since your birth you'd say exactly the same thing). I agree with both points but that does not invalidate what I said abour alphabetic ordering being artificial.
- kragen 7y agoRight, `min` makes sense for lattices too, not just total orders.
- Tyr42 7y agoIt's pretty nice to have min work on tuples, so I can make my min-heap take in (distance_so_far, (x,y)) when doing pathfinding.
- pwdisswordfish2 7y agoAn empty list is a list of anything. If it were not a list of anything, it would not be a list at all.
- dooglius 7y agoYou could make an artificial min/max of all types object that gets returned on empty lists
- int_19h 7y agomin/max(X) is expected to return some Y for which (Y in X) is true.