[Tutor] Is there a test for hashability?

Richard D. Moores rdmoores at gmail.com
Thu Sep 1 17:28:26 CEST 2011

Thanks, James, from your ideas I've come up with this function as a
general test for hashibility of any object:

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

But is it?  It returns True for ints, floats, sets, tuples, strings,
functions; and False for lists


More information about the Tutor mailing list