<br><br><div class="gmail_quote">On Thu, Sep 1, 2011 at 11:37 AM, Hugo Arts <span dir="ltr"><<a href="mailto:hugo.yoshi@gmail.com">hugo.yoshi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Thu, Sep 1, 2011 at 5:28 PM, Richard D. Moores <<a href="mailto:rdmoores@gmail.com">rdmoores@gmail.com</a>> wrote:<br>
> Thanks, James, from your ideas I've come up with this function as a<br>
> general test for hashibility of any object:<br>
><br>
> def is_hashable(object):<br>
> try:<br>
> if hash(object):<br>
> return True<br>
> except TypeError:<br>
> return False<br>
><br>
> But is it? It returns True for ints, floats, sets, tuples, strings,<br>
> functions; and False for lists<br>
><br>
> Dick<br>
<br>
</div></div>Are you sure? In my testing it returns False for sets, but True for<br>
frozensets as it should.<br>
</blockquote></div><br><div>I agree with hugo, I just tested with all of these:</div><div><br></div><div><div>a = 'a'</div><div>b = []</div><div>c = 1</div><div>d = ()</div><div>e = set()</div><div>f = frozenset()</div>
</div><div><br></div><div>it gave the correct response for each</div><div><br></div><div><div>a = 'a' - True</div><div>b = [] - False</div><div>c = 1 - True</div><div>d = () - True</div><div>e = set() - False</div>
<div>f = frozenset() - True</div></div>