[Python-ideas] Disallow orderring comparison to NaN
Rob Cliffe
rob.cliffe at btinternet.com
Thu Apr 28 18:17:46 CEST 2011
On 28/04/2011 17:00, Steven D'Aprano wrote:
> Mike Graham wrote:
>> On Thu, Apr 28, 2011 at 10:01 AM, Steven D'Aprano
>> <steve at pearwood.info> wrote:
>>> I think I would like to see a demonstration of this rather than just
>>> take
>>> your word for it.
>>
>> One demonstration would be
> [snip]
>
> Thank you.
>
> Nevertheless, that does appear to be an easy fix:
>
>
> def bubble_sort(xs):
> while True:
> changed = False
> for i in range(len(xs) - 1):
> # don't use `not (xs[i] < xs[i + 1])` as that fails in the
> # presence of NANs
> if xs[i] >= xs[i + 1]:
> changed = True
> xs[i], xs[i + 1] = xs[i + 1], xs[i]
> if not changed:
> break
>
>
>
True. But why be forced to walk on eggshells when writing a perfectly
ordinary bit of code that "ought" to work as is?
Rob Cliffe
More information about the Python-ideas
mailing list