[Tutor] Is there a test for hashability?
Chris Fuller
cfuller084 at thinkingplanet.net
Fri Sep 2 00:42:02 CEST 2011
On Thursday 01 September 2011, Richard D. Moores wrote:
> 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
It's a style issue, really. Either would be fine, but I don't like mixing
code-flow disrupting actions when it's easily avoided.
Cheers
More information about the Tutor
mailing list