Mark Dickinson <[email protected]> added the comment:
Agreed with Raymond and Tim here that the sorting functionality itself
shouldn't be special-cased for nans.
[Tim]
> So people who go down this path can't get two steps before making a fork in
> the road ;-)
Well, both those solutions are wrong. *Clearly*, negative NaNs should be sorted
to the start of the list, while positive NaNs are sorted to the end of the
list. (Yes, I'm joking, but only a little bit: that's the result you'd get if
you used IEEE 754's totalOrder to sort. But it's difficult to see how it would
be useful in practice, given that people usually don't know about or care about
the sign that their NaN has.)
Maybe the solution would be to provide an official "math.total_order" function
that can be used as a key:
sorted(my_list_of_floats_with_nans_in_it, key=math.total_order)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36095>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com