What is wrong in my list comprehension?

J Kenneth King james at agentultra.com
Mon Feb 2 11:33:02 EST 2009


Chris Rebert <clp2 at rebertia.com> writes:

> Python 2.6 (r26:66714, Nov 18 2008, 21:48:52)
> [GCC 4.0.1 (Apple Inc. build 5484)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> bool(-1)
> True
>
> str.find() returns -1 on failure (i.e. if the substring is not in the
> given string).
> -1 is considered boolean true by Python.

That's an odd little quirk... never noticed that before.

I just use regular expressions myself.

Wouldn't this be something worth cleaning up? It's a little confusing
for failure to evaluate to boolean true even if the relationship isn't
direct.



More information about the Python-list mailing list