[Tutor] Is there a test for hashability?

Richard D. Moores rdmoores at gmail.com
Thu Sep 1 22:58:59 CEST 2011


On Thu, Sep 1, 2011 at 12:29, Chris Fuller
<cfuller084 at thinkingplanet.net> wrote:


> *Ahem*
>
> def is_hashable(object):
>   try:
>        hash(object)
>    except TypeError:
>        return False
>
>    return True

Why is that preferred to

def is_hashable(object):
    try:
        hash(object)
        return True
    except TypeError:
        return False

??

Dick


More information about the Tutor mailing list