float("nan") in set or as key

Chris Angelico rosuav at gmail.com
Fri Jun 3 00:35:52 EDT 2011


On Fri, Jun 3, 2011 at 2:23 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>> You can't get a valid result from data produced by an invalid
>> computation. Garbage in, garbage out.
>
> Of course you can. Here's a trivial example:
>
> def f(x):
>    return 1
>

If your incoming x is garbage, your outgoing 1 is also garbage. Later
on, you can use 'isgarbage(x)' to find out whether anything went
wrong. You can also use 'isinsane(self)', which is defined as follows:

class Programmer:
  def isinsane(self):
    return True if float("nan")==float("nan") else True

Chris Angelico



More information about the Python-list mailing list