SHARE
TWEET

Untitled

a guest Jul 3rd, 2010 121 Never
  1. In [138]: class bad(object):
  2.     def __init__(self, str):
  3.         self._str = str
  4.     def __repr__(self):
  5.         return repr(self._str)
  6.     def __hash__(self):
  7.         return 1
  8.    .....:
  9.  
  10. In [145]: set([bad("cat"), bad("dog"), bad("fish")])
  11. Out[145]: set(['cat', 'fish', 'dog'])
  12.  
  13. In [146]: [hash(i) for i in set([bad("cat"), bad("dog"), bad("fish")])]
  14. Out[146]: [1, 1, 1]
RAW Paste Data
Top