On Sun, Dec 29, 2019 at 5:14 PM David Mertz <me...@gnosis.cx> wrote: > As me and Uncle Timmy have pointed out, it IS FIXED in sorted(). You just > need to call: > > sorted_stuff = sorted(stuff, key=nan_aware_transform) >
But what would that be? floats have inf and -inf -- so how could you force the NaNs to be at the end or beginning? (or anywhere else determinant? (though replacing NaN with inf would push all teh NaNs and inf to the end, in arbitrary order, but who's to know whether a NaN is bigger than inf anyway. You could provide a custom cmp() function, though, which would be slower, probably slower than pre-filtering the values. And I just noticed that Python3 removed it anyway. But it wouldn't "fix" median anyway -- you'd still need to do something with those NaNs -- I guess saying "all NaNs" are larger than any other value" would al least provide consistent results, but they wouldn't be meaningful. The only option for a meaningful result is to remove them. Raising, of course, is also correct. -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QMYGI57ONMBBXUVDJLVPFUBS3RJXVG67/ Code of Conduct: http://python.org/psf/codeofconduct/